[英]Copy local = false file not found exception issue
Hi I know this has been asked but it did not get an answer.嗨,我知道有人问过这个问题,但没有得到答复。 I have a problem when I want to use a dll that is installed on C:\\Program files (x86)\\Dummu_API.dll
当我想使用安装在 C:\\Program files (x86)\\Dummu_API.dll 上的 dll 时遇到问题
When I run my app it throws exception:当我运行我的应用程序时,它抛出异常:
Could not load file or assembly 'Dummy_API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
无法加载文件或程序集“Dummy_API,版本=1.0.0.0,文化=中性,PublicKeyToken=null”或其依赖项之一。 The system cannot find the file specified.
该系统找不到指定的文件。
My project have the reference as Copy Local = false and specific version = false.我的项目引用为 Copy Local = false 和特定版本 = false。 My project also is a x86 platform target.
我的项目也是一个 x86 平台目标。
I don´t know why my app don't find the assembly.我不知道为什么我的应用找不到程序集。 Any Idea what it is happening?
知道发生了什么吗?
Option 1选项1
You can tell your application that you will resolve the Assemblies yourselves if not found in references.您可以告诉您的应用程序,如果没有在参考文献中找到,您将自己解决程序集。 To do that:
要做到这一点:
In your applications main method attach assembly resolver:在您的应用程序主要方法中附加程序集解析器:
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
Make sure you are not using the dynamically resolved assembly in your main method.确保您没有在 main 方法中使用动态解析的程序集。
Your resolver method code (This is where you load an assembly - look at ResolveEventArgs I have just hard coded one but you can resolve various assemblies from different locations here)您的解析器方法代码(这是您加载程序集的地方 - 查看 ResolveEventArgs 我刚刚硬编码了一个,但您可以在此处解析来自不同位置的各种程序集)
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
return Assembly.LoadFile(@"C:\temp\ClassLibrary1.dll");
}
Option 2选项 2
Add this to your app.config (Only works for application base directory's sub folders)将此添加到您的 app.config (仅适用于应用程序基目录的子文件夹)
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="PathToMyAssemblies\" />
</assemblyBinding>
</runtime>
So the file is not in the GAC, and there is not a local copy.所以该文件不在 GAC 中,也没有本地副本。 You've eliminated the only two places it could be loading from - I don't know why you are expecting this to work.
您已经消除了它可以从中加载的仅有的两个位置 - 我不知道您为什么期望它起作用。
You need to set Copy Local=true or install Dummy_API.dll into the Global Assembly Cache on the machine that will be running your code.您需要设置 Copy Local=true 或将 Dummy_API.dll 安装到将运行您的代码的机器上的全局程序集缓存中。 One or the other.
非此即彼。
I don`t know if you chose the right project type, as for me, I found me selecting the dot net core type(console app) project at the very beginning, then I shifted the project to dot net framework(console app), and it works for me.不知道你选对了项目类型,至于我,我发现我一开始选择了dot net core type(console app)项目,然后我把项目转移到了dot net framework(console app),它对我有用。
There`s another quick way to check if you have the same issue as I do:还有另一种快速方法可以检查您是否和我有同样的问题:
Just a hint or tip, hope helped!只是一个提示或提示,希望有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.