复制本地=未发现假文件中的异常问题 [英] Copy local = false file not found exception issue
问题描述
您好我知道这<一href="https://stackoverflow.com/questions/17837609/c-sharp-copy-local-false-referenced-project-shows-could-not-load-file-or">has有人问,但它并没有得到答案。 我有一个问题,当我要使用安装在℃的DLL:\ Program Files文件(x86)的\ Dummu_API.dll
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
当我运行我的应用程序,它抛出异常:
When I run my app it throws exception:
无法加载文件或程序集Dummy_API,版本= 1.0.0.0,文化=中性公钥= null或它的一个依赖。该系统找不到指定的文件。
Could not load file or assembly 'Dummy_API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
我的项目有参考的复制本地=虚假和特定版本= FALSE。我的项目也是一个x86平台的目标。
My project have the reference as Copy Local = false and specific version = false. My project also is a x86 platform target.
我不知道为什么我的应用程序没有找到组装。知不知道这是怎么回事?
I don´t know why my app don't find the assembly. Any Idea what it is happening?
推荐答案
选项1 的
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;
确保你没有使用动态解析组件的主要方法。
您解析方法code(这是你加载程序集 - 看ResolveEventArgs我只是很难codeD之一,但你可以解决从这里不同的地点不同的组件)
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");
}
选项2 的
Option 2
添加到您的app.config(仅适用于应用程序根目录的子文件)
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>
这篇关于复制本地=未发现假文件中的异常问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!