[英]“Copy Local = false” referenced project shows “Could not load file or assembly”
[英]Copy local = false file not found exception issue
选项1
您可以告诉您的应用程序,如果没有在参考文献中找到,您将自己解决程序集。 要做到这一点:
在您的应用程序主要方法中附加程序集解析器:
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
确保您没有在 main 方法中使用动态解析的程序集。
您的解析器方法代码(这是您加载程序集的地方 - 查看 ResolveEventArgs 我刚刚硬编码了一个,但您可以在此处解析来自不同位置的各种程序集)
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
return Assembly.LoadFile(@"C:\temp\ClassLibrary1.dll");
}
选项 2
将此添加到您的 app.config (仅适用于应用程序基目录的子文件夹)
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="PathToMyAssemblies\" />
</assemblyBinding>
</runtime>
所以该文件不在 GAC 中,也没有本地副本。 您已经消除了它可以从中加载的仅有的两个位置 - 我不知道您为什么期望它起作用。
您需要设置 Copy Local=true 或将 Dummy_API.dll 安装到将运行您的代码的机器上的全局程序集缓存中。 非此即彼。
不知道你选对了项目类型,至于我,我发现我一开始选择了dot net core type(console app)项目,然后我把项目转移到了dot net framework(console app),它对我有用。
还有另一种快速方法可以检查您是否和我有同样的问题:
只是一个提示或提示,希望有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.