[英]Weird Error: System.IO.FileNotFoundException: Could not load file or assembly
I have 2 projects, 我有两个项目
The first project C# project where I have a blank form(new project). 我有空白表格的第一个项目C#项目(新项目)。 I am compiling this form as a dll so I can reference the form. 我将此表格编译为dll,因此可以引用该表格。
The VB project is an ExcelDNA project which consists of a custom task pane with a button to open the form,the task pane works fine. VB项目是一个ExcelDNA项目,由一个自定义任务窗格和一个用于打开表单的按钮组成,该任务窗格可以正常工作。 However, I get the following error when clicking the Button: 但是,单击按钮时出现以下错误:
System.IO.FileNotFoundException: Could not load file or assembly
I can get this to work by creating a UserControl in the VB project, and then accessing it via the Button, however I have the form written in C# already and do not want to convert it to VB. 我可以通过在VB项目中创建UserControl,然后通过Button访问它来使它起作用,但是我已经用C#编写了表单,并且不想将其转换为VB。
There is no need to convert the project to VB.NET. 无需将项目转换为VB.NET。 This error is because the .net runtime cannot find the assembly (dll or exe that contains your first form). 该错误是因为.net运行时找不到程序集(包含您的第一个窗体的dll或exe)。 In Visual Studio, open the Solution Explorer
window and expand the References
node. 在Visual Studio中,打开“ Solution Explorer
窗口,然后展开“ References
节点。 Right-click the reference to your first assembly and click Properties
. 右键单击对第一个装配的引用,然后单击Properties
。 In the properties window change the Copy Local
as True
. 在属性窗口中, Copy Local
更改为True
。
This way Visual Studio will copy the assembly to the output folder of the project ('bin\\Debug' or 'bin\\Release'). 这样,Visual Studio会将程序集复制到项目的输出文件夹(“ bin \\ Debug”或“ bin \\ Release”)。
因此,解决方案是确保将窗体Dll复制到Excel加载项所在的目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.