使用 dll 方法时出现 FileNotFoundException
在 Visual Studio 中,我有一个包含多个项目的解决方案。在一个项目中,我添加了对另一个项目的引用。一切都很好。我可以在自动完成中看到另一个项目的名称空间/类等。
当我尝试这样做时,
OtherProjectNamespace.Class a = new OtherProjectNamespace.Class();
我得到了这个:
Could not load file or assembly '**OtherProjectNamespace**, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
没有行,什么都没有,我尝试尝试...捕获新行,甚至没有捕获例外。
可能是什么原因?
谢谢, 卡洛斯
in Visual Studio I have a solution with several projects. In one project I added a reference to another project. All fine. I can see the namespaces/classes of the another project in autocomplete, etc.
When I try to do
OtherProjectNamespace.Class a = new OtherProjectNamespace.Class();
I'm getting this:
Could not load file or assembly '**OtherProjectNamespace**, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
There is no line, nothing, I tried try... catch around the new line and is not even catching the exception.
What could be the cause?
Thanks,
Carlos
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一些可能的方向:
您尝试创建的类是否依赖于另一个程序集中的类?如果是,请尝试添加对第三个程序集的引用。
程序集是否已复制到应用程序的运行目录?确保引用的
Copy Local
属性设置为true
。如果仍然无法解决问题,请使用 Fusion Log View 等工具(Visual Studio 附带,从 VS 命令行运行
fuslogvw.exe
)来获取日志的准确名称丢失的文件,以及 CLR 尝试加载该文件的位置。也许这样你会找到另一个需要复制的文件。Some possible directions:
Does the class you are trying to create have any dependency on a class in another assembly? If it does, try adding a reference to the third assembly.
Did the assembly get copied to the running directory of your application? Ensure that the
Copy Local
property of the reference is set totrue
.If you still don't resolve the problem, use a tools such as Fusion Log View (comes with Visual Studio, run
fuslogvw.exe
from VS command line) to get the exact name of the file that was missing, and the locations from which the CLR tried to load it. Maybe this way you'll find another file that you need to copy.试试这个:
在项目引用中,将“特定版本”属性更改为 false。右键单击该项目并选择“清理”。然后重建项目。
Try this:
In the project references, change the "Specific Version" property to false. Right click on the project and select Clean. Then rebuild the project.