Copy local = false file not found exception issue

允我心安 提交于 2019-12-02 02:06:36

Option 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.

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)

static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    return Assembly.LoadFile(@"C:\temp\ClassLibrary1.dll");
}

Option 2

Add this to your app.config (Only works for application base directory's sub folders)

<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. 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. One or the other.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!