无法添加参考.NET [英] cannot add a reference .NET

查看:37
本文介绍了无法添加参考.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DLL,我想添加它作为对我的项目的引用,但是每次尝试执行此操作时,都会弹出一个对话框,告诉我:

I have a DLL which I would like to add as a reference to my project, but everytime I try to do it a dialog pops up telling me:

无法添加参考.请确保该文件是可访问的,并且是有效的程序集或COM组件.

The reference could not be added. Please make sure that the file is accesible, and that it is a valid assembly or COM component.

我研究了一下,发现错误是因为程序集不受.NET的管理,我应该使用DLLImport Attribute,但是,我在另一台计算机上有相同的精确解决方案,并且Everythig都可以正常工作.

I have researched a little and found out that error is because the assembly is unmanaged by .NET and that I should use DLLImport Attribute, however, I have the same exact solution in another computer, and everythig just works fine.

区别在于我要添加引用的新计算机是x64,而旧计算机是x86.

The difference is that the new computer I'm trying to add the reference is x64 and the old one is x86.

我同时拥有x64和x86 DLL,并且无法添加任何文件.为什么会这样?

I have both the x64 and x86 DLL's, and can't add any. Why is this happening?

推荐答案

无论32/64的位数"如何,都不能在Visual Studio中将非托管DLL添加为引用.而且我怀疑它是否可以在您的x86机器上正常工作.

You can not add unmanaged DLLs as references in Visual Studio, regardless of the 32/64 "bittyness". And I doubt that it worked on your x86 machine.

常规" DLL和COM-DLL之间有区别.

There's a difference between "normal" DLLs and COM-DLLs.

您可以在向系统注册COM-DLL之后添加对它的引用(实际上,您引用的是公开的COM对象,并且该DLL的引用会自动添加).这可以在添加参考"对话框的"COM"-选项卡上完成(在大多数情况下,您必须确保将项目构建为x86目标).

You can add a reference to a COM-DLL after it was registered with the system (actually you reference the exposed COM object and a reference to the DLL is added automatically). This can be done on the "COM"-Tab of the "Add reference" dialog (here you have to make sure that your project is built as a x86 target in most cases).

正常"的DLL可以-就像我说的-根本不添加.您可以在解决方案中包括(右键单击解决方案,选择添加现有文件"),但是除非您声明类似

"normal" DLLs can - as I said - not be added at all. You can include them in the solution (right click solution, select "Add existing file"), but they will not be referenced unless you declare something like

[DllImport("...")]
public static extern void MyFunction();

我怀疑在您的其他解决方案中,您实际上是在引用某种包装DLL,并且其中包含DLL导入.

I suspect that in your other solution, there's some kind of wrapper DLL, which you are actually referencing and which contains the DLL imports.

这篇关于无法添加参考.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆