简体   繁体   English

VS2010找不到当前上下文,但建立了引用

[英]VS2010 does not find current context yet the reference is built

I'm building an application using Visual Studio 2010 in which I have to use an external dll. 我正在使用Visual Studio 2010构建一个应用程序,我必须使用外部DLL。 While I'm coding, the IDE is not showing to me any errors about methods owned by this dll I added to my project. 在我编码的时候,IDE没有向我展示我添加到项目中的这个dll所拥有的方法的任何错误。 I can even browse the class object hierarchy. 我甚至可以浏览类对象层次结构。 Once I try to compile my project, this reference is lost. 一旦我尝试编译我的项目,这个引用就会丢失。 I can't browse the reference anymore and I'm getting the usual error "does not exists in the current context". 我不能再浏览引用了,我得到了通常的错误“当前上下文中不存在”。 I've even recompiled the dll but I'm still having this error. 我甚至重新编译了dll,但我仍然有这个错误。

In your Project's properties, click on the "Application" tab. 在项目的属性中,单击“应用程序”选项卡。 Check and see what the "Target Framework" is set to. 检查并查看“目标框架”的设置。 I was encountering something similar to this before and it was all because the Target Framework was set to ".NET Framework 4 Client Profile" instead of ".NET Framework 4." 之前我遇到过类似的事情,这完全是因为Target Framework被设置为“.NET Framework 4 Client Profile”而不是“.NET Framework 4”。

Edit 编辑

I'm not exactly sure why this solved the issue in my case with missing references, but it did work. 我不确定为什么在我的情况下解决了缺少引用的问题,但它确实有效。 I was following the recommendation of another SO link that I'll add if I can find again. 我正在按照另一个SO链接的建议,如果我能再次找到,我将添加。

you will get this error if 如果你得到这个错误

Your DLL project targeting different .NET Framework version than your project who uses this DLL 您的DLL project目标是 project who uses this DLL DLL project 不同的.NET Framework版本

so make sure that your Referenced Project (DLL Provider) is using the same version of .NET Framework that your other project (DLL consumer) uses 因此,请确保您的Referenced Project (DLL Provider) using the same version of .NET Framework您的other project (DLL consumer)使用using the same version of .NET Framework

Try to check whether Visual Studio has set the Path to your dll correctly: 尝试检查Visual Studio是否已正确设置路径到您的DLL:

Right-click the dll and go to Properties. 右键单击dll,然后转到“属性”。 Then in the properties window you have one line stating the physical path to the dll. 然后在属性窗口中,您有一行说明dll的物理路径。

I sometimes had the problem that this line was empty and therefor the dll was marked with a yellow questionmark. 我有时会遇到这条线是空的问题,因此dll标有黄色问号。

If the line is empty filling in the correct path to your dll my solve your problem. 如果该行为空,填写正确的dll路径,我就可以解决您的问题。

hope that helps, cheers 希望有所帮助,欢呼

It could be an issue with the platform your project is targeting and the platform of the dll. 这可能是您的项目所针对的平台和dll平台的问题。 Try specifying explicitly x86 or 64 and see what happens. 尝试明确指定x86或64,看看会发生什么。 If it work, then check if you are happy with that platform or if you will need to find the dll compiled for the other or if you will need to find another library. 如果它有效,那么检查您是否对该平台感到满意,或者您是否需要找到为其他平台编译的dll,或者您是否需要找到另一个库。

Hope it helps 希望能帮助到你

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

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