简体   繁体   English

Copy local = false file not found 异常问题

[英]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:还有另一种快速方法可以检查您是否和我有同样的问题:

  1. After you create item app.config and compiled it, you found .dll.config but not .exe.config创建项目 app.config 并编译后,您找到了 .dll.config 但没有找到 .exe.config
  2. Reference tab replaced by dependencys tab引用选项卡替换为依赖项选项卡
  3. Project property framework selection can only be core xx or net 5.0 but not framework 3.0/4.0/4.5 etc.项目属性框架选择只能是core xx或net 5.0,不能是framework 3.0/4.0/4.5等。

Just a hint or tip, hope helped!只是一个提示或提示,希望有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 引用的项目“ Copy Local = false”显示“无法加载文件或程序集” - “Copy Local = false” referenced project shows “Could not load file or assembly” 在WPF中,在部署XAML解析时,如果将其他本地dll的本地副本设置为false,则会从表示框架dll抛出异常 - In WPF, While deploying XAML parse exception thrown from presentation framework dll when set copy local as false for other dlls 在本地网络中复制文件 - Copy File in local Network OpenTK 文件未找到异常 - OpenTK file not found exception 找不到错误的文件异常 - Wrong file not found exception 找不到文件异常发生 - File not found Exception occurs 将文件复制到Win 8中的本地文件夹 - Copy file to Local folder in Win 8 如何在解决方案中设置所有项目以复制本地false - how to set all projects in solution to copy local false 在测试服务器上的IIS中找不到文件异常/w3wp.exe问题,但在IIS Express中本地没有问题 - File not found exception/w3wp.exe issue in IIS on test server but no issues in IIS Express locally 例外:找不到适用于jdbc:derby:\\\\ serveraddress \\ db; create = false的驱动程序 - Exception: No suitable driver found for jdbc:derby:\\serveraddress\db;create=false
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM