简体   繁体   English

C#:添加DLL参考

[英]C#: Adding DLL Reference

Preface: I know basically nothing about C#. 前言:我基本上对C#一无所知。 I've added a dll to my project. 我已经在项目中添加了一个dll。 I have no build errors, but when I try to run, I get an error that says it can't find the dll. 我没有构建错误,但是当我尝试运行时,我收到一条错误消息,说它无法找到dll。 I've tried copying it to the output directories too. 我也尝试过将它复制到输出目录中。 To no avail. 无济于事。

Any idea what could be happening? 知道会发生什么吗?

Specific Error: 具体错误:

System.IO.FileNotFoundException was unhandled Message=Could not load file or assembly 'controllib_clr.dll' or one of its dependencies. System.IO.FileNotFoundException未处理Message =无法加载文件或程序集'controllib_clr.dll'或其依赖项之一。 The specified module could not be found. 指定的模块无法找到。 Source=controllib_demo_cs... 来源= controllib_demo_cs ...

I'll be happy to add more information if need be. 如果需要,我会很乐意添加更多信息。 :) I just don't know what info would be beneficial given my (very) limited knowledge. :)我只是不知道鉴于我(非常)有限的知识,哪些信息会有所帮助。

看来它无法找到/加载一些依赖项dll,我将使用DependencyWalker找出丢失的内容http://www.dependencywalker.com/

If it exists, in your output folder, then most likely its one of its dependencies that is missing. 如果存在,则在您的输出文件夹中,很可能缺少依赖项之一。 You can fix this by adding its dependencies as references in your project. 您可以通过在项目中添加其依赖项作为引用来解决此问题。

if it doesn't exist in your output, then, check that "Copy Local" is set in the properties of the reference. 如果输出中不存在,则检查在引用的属性中是否设置了“复制本地”。

Is it a managed (.NET) or an unmanaged (native) DLL? 它是托管(.NET)还是非托管(本机)DLL? I'm assuming unmanaged. 我假设不受管理。

FileNotFoundException is commonly thrown when missing a dependency. 缺少依赖项时通常会抛出FileNotFoundException。 The DLL you are loading might require any number of other DLLs on load. 您加载的DLL可能需要加载任意数量的其他DLL。 In most cases it won't tell you which file it needs. 在大多数情况下,它不会告诉您所需的文件。 You have to refer to the documentation for that DLL. 您必须参考该DLL的文档。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM