Visual Studio抛出“错误"消息.编译时异常 [英] Visual Studio is throwing a "wrong" compile time exception

查看:68
本文介绍了Visual Studio抛出“错误"消息.编译时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在Mono中部署我的项目,我已经将其降级为.Net 4.0,就像对引用的库(CommonUtils)所做的那样.但是,我仍然遇到以下异常:

无法解析主要参考"CommonUtils",因为它间接依赖于针对".NETFramework,版本= v4.5框架.此版本比当前目标框架".NETFramework,Version = v4.0"更高.

我试图解决的问题:

  • 我已经在两个项目中重新安装了所有Nuget软件包
  • 我已经多次尝试清理项目/解决方案,删除所有bin/obj文件夹并重建所有内容
  • 我已经更改了程序集的名称,以确保不缓存任何内容

这些都没有帮助.

两个项目都设置为编译为.Net 4.0.参考是通过将已编译的程序集 CommonUtils 复制到"ExternalLibraries"文件夹中的,因为此DLL也用于其他项目中.

右键单击Newtonsoft.Json.dll,将其与 CommonUtils 一起移至 bin 文件夹-在详细信息/文件说明: Json"中显示.NET .NET 4.0

我非常确定我对.net 4.0拥有正确的一切,并且Visual Studio还允许我添加该库并以自动完成功能支持我,只是编译时会抛出上述警告.作为警告的结果,突然我得到一个例外,即 CommonUtils 所引用的类型都不存在

找不到名称空间名称'CommonUtils'的类型(您是否缺少using指令或程序集引用?)

还有什么我可以尝试做的?

PS:几年前,我遇到了类似的问题,其中使用了旧程序集进行编译,并通过从头开始设置Windows和Visual Studio来解决"它,但我只是不想这样做时间.

更新:

它可以在另一台计算机上工作:我已经通过USB记忆棒将文件夹结构带到了另一台具有相同OS(Windows 8.1)和相同Visual Studio 2013的计算机上-据我所知,两台计算机都应具有所有已安装更新-并且在那里有效.

将USB记忆棒和已成功编译的项目带回到我的PC上-我仍然遇到相同的错误.

(我知道,这意味着两台计算机不可能都安装相同的东西,但是我不知道如何找到差异,也许有些提示可能会导致这种方式出错吗?)


更新2:

Process Explorer并没有太大帮助,但是当我使用诊断日志编译所有内容时,我认为我得到了关键提示:

  ...5>统一的主要参考资料"Newtonsoft.Json,版本= 6.0.0.0,文化=中性,PublicKeyToken = 30ad4fe6b2a6aeed".(TaskId:158)5>由于文件"Web.config"中的绑定重定向条目,因此在"C:\< SolutionFolder> \ packages \ WebGrease.1.6.0 \ lib \ WebGrease.dll"中使用此版本而不是原始版本"4.5.0.0".(TaskId:158)5>由于绑定重定向条目,因此在"C:\ Program Files(x86)\ Microsoft ASP.NET \ ASP.NET MVC 4 \ Assemblies \ System.Web.Http.dll"中使用此版本而不是原始版本"4.5.0.0"在文件"Web.config"中.(TaskId:158)5>由于存在绑定,因此在"C:\ Program Files(x86)\ Microsoft ASP.NET \ ASP.NET MVC 4 \ Assemblies \ System.Net.Http.Formatting.dll"中使用此版本而不是原始版本"4.5.0.0"重定向文件"Web.config"中的条目.(TaskId:158)5>解析的文件路径为"C:\< SolutionFolder> \ packages \ Newtonsoft.Json.6.0.3 \ lib \ net40 \ Newtonsoft.Json.dll".(TaskId:158)5>在搜索路径位置"{HintPathFromItem}"中找到引用.(TaskId:158)5>找到相关文件"C:\< SolutionFolder> \ packages \ Newtonsoft.Json.6.0.3 \ lib \ net40 \ Newtonsoft.Json.xml".(TaskId:158)5>此参考的ImageRuntimeVersion是"v4.0.30319".(TaskId:158)... 

但是,我在生成该版本的另一台计算机上也得到了完全相同的消息.

此外,两台计算机的开头都显示此行:

 正在跳过NuGet软件包Newtonsoft.Json 6.0.3,因为它已经安装. 

在这种情况下,已安装是什么意思?那NuGet下载了吗?还是它在GAC中的某个地方,但是我找不到它?(请参阅评论)

在编译工作的机器上,我还获得了以下输出:

  1>依赖关系"Newtonsoft.Json,版本= 4.5.0.0,文化=中性,PublicKeyToken = 30ad4fe6b2a6aeed".(TaskId:17)1>解决的文件路径是"C:\ Program Files(x86)\ Microsoft Visual Studio 12.0 \ Blend \ Newtonsoft.Json.dll".(TaskId:17)1>在搜索路径位置"{Registry:Software \ Microsoft \ .NETFramework,v4.0,AssemblyFoldersEx}"中找到引用.(TaskId:17)1>对于SearchPath"C:\ Program Files(x86)\ Microsoft ASP.NET \ ASP.NET MVC 4 \ Assemblies".(TaskId:17)1>被视为"C:\ Program Files(x86)\ Microsoft ASP.NET \ ASP.NET MVC 4 \ Assemblies \ Newtonsoft.Json.winmd",但它不存在.(TaskId:17)1>被视为"C:\ Program Files(x86)\ Microsoft ASP.NET \ ASP.NET MVC 4 \ Assemblies \ Newtonsoft.Json.dll",但它不存在.(TaskId:17)1>被视为"C:\ Program Files(x86)\ Microsoft ASP.NET \ ASP.NET MVC 4 \ Assemblies \ Newtonsoft.Json.exe",但它不存在.(TaskId:17)1>对于SearchPath"{TargetFrameworkDirectory}".(TaskId:17)1>被视为"C:\ Program Files(x86)\参考程序集\ Microsoft \ Framework \ .NETFramework \ v4.0 \ Newtonsoft.Json.winmd",但它不存在.(TaskId:17)1>被视为"C:\ Program Files(x86)\参考程序集\ Microsoft \ Framework \ .NETFramework \ v4.0 \ Newtonsoft.Json.dll",但它不存在.(TaskId:17)1>被视为"C:\ Program Files(x86)\参考程序集\ Microsoft \ Framework \ .NETFramework \ v4.0 \ Newtonsoft.Json.exe",但它不存在.(TaskId:17)1>对于SearchPath"{Registry:Software \ Microsoft \ .NETFramework,v4.0,AssemblyFoldersEx}".(TaskId:17)1>考虑的AssemblyFoldersEx位置.(TaskId:17)1>由"CommonUtils"要求.(TaskId:17)1>此参考的ImageRuntimeVersion是"v4.0.30319".(TaskId:17) 

但是我在编译失败的计算机上看不到

最终更新:

我放弃并重新安装了整个系统-现在可以正常工作,但是它不能回答错误的Newtonsoft.Json.dll来自何处以及为什么它没有出现在GAC中的问题,我终于可以再次在那个项目上工作.

我实际上很失望,它不像在maven中那样简单,在maven中,您只可以删除一个文件夹以使maven重新下载所有库.

我在VHD上有损坏的系统的映像,因此,如果其他人提出了很好的解决方案,我可以在VM中进行尝试.

解决方案

我遇到了同样的问题,解决方案是删除位于 c:\中的 Newtonsoft.json.dll .程序文件\ Microsoft SDKs \ Windows Azure \ .NET SDK \ v2.3 \ ref

连接错误报告中将其描述为解决方法./p>

原始错误报告已删除,可能存在新的/相关的/相同的问题: https://connect.microsoft.com/VisualStudio/feedback/details/816985

In order to deploy my project in Mono, I've downgraded it to .Net 4.0 as I've done with the library which I'm referencing (CommonUtils). However, I'm still getting the following exception:

The primary reference "CommonUtils" could not be resolved because it has an indirect dependency on the assembly "Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" which was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".

What I've tried to resolve the issue:

  • I've re-installed all Nuget packages in both projects
  • I've multiple times tried to clean the projects / solutions, delete all bin/obj folder an rebuild everything
  • I've changed the name of the assembly in order to be sure nothing is cached

None of this helped.

Both projects are set to be compiled as .Net 4.0. The reference is by copying the compiled assembly CommonUtils into an "ExternalLibraries"-folder, since this DLL is also used in other projects.

Right-click on Newtonsoft.Json.dll - which is moved to the bin folder together with CommonUtils - shows in Details/File description: Json.NET .NET 4.0

I am pretty sure that I have everything correct for .net 4.0 and Visual Studio also lets me add the library and supports me with auto-completion, just the compiling throws the mentioned warning. As a result of the warning, suddenly I get exceptions that none of the types referenced from CommonUtils exists

The type of namespace name 'CommonUtils' could not be found (are you missing a using directive or an assembly reference?)

What else can I try to make this work?

PS: I had a similar problem few years ago, where an old assembly was used for compiling, and "solved" it by literally setting up windows and visual studio from scratch, but I just don't feel like doing it this time.

Update:

It works on another computer: I've taken the folder structure via USB Stick to another computer with the same OS (Windows 8.1) and the same Visual Studio 2013 - as far as I can tell, both computers should have all the updates installed - and there it works.

Taking the USB Stick with the successfully compiled project back to my PC - I'm still getting the same errors.

(I understand, this means that both computers can't possibly have everything the same installed, but I wouldn't know how to find the difference, maybe some hint with what can be wrong this way?)


Update 2:

Process explorer didn't help too much, but when I compiled everything with diagnostic log, I think I got the key hint:

...
5>  Unified primary reference "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". (TaskId:158)
5>      Using this version instead of original version "4.5.0.0" in "C:\<SolutionFolder>\packages\WebGrease.1.6.0\lib\WebGrease.dll" because of a binding redirect entry in the file "Web.config". (TaskId:158)
5>      Using this version instead of original version "4.5.0.0" in "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Http.dll" because of a binding redirect entry in the file "Web.config". (TaskId:158)
5>      Using this version instead of original version "4.5.0.0" in "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Net.Http.Formatting.dll" because of a binding redirect entry in the file "Web.config". (TaskId:158)
5>      Resolved file path is "C:\<SolutionFolder>\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll". (TaskId:158)
5>      Reference found at search path location "{HintPathFromItem}". (TaskId:158)
5>      Found related file "C:\<SolutionFolder>\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.xml". (TaskId:158)
5>      The ImageRuntimeVersion for this reference is "v4.0.30319". (TaskId:158)
...

However, I get the exact same message also on the other computer where the build is working.

Additionally both computers show this line in the beginning:

Skipping NuGet package Newtonsoft.Json 6.0.3 since it is already installed.

What does installed mean in this context? that NuGet downloaded it? or is it somewhere in the GAC, but I couldn't find it? (see comments)

And on the machine, where the compilation works, I get additionally this output:

1>  Dependency "Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". (TaskId:17)
1>      Resolved file path is "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll". (TaskId:17)
1>      Reference found at search path location "{Registry:Software\Microsoft\.NETFramework,v4.0,AssemblyFoldersEx}". (TaskId:17)
1>          For SearchPath "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies". (TaskId:17)
1>          Considered "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\Newtonsoft.Json.winmd", but it didn't exist. (TaskId:17)
1>          Considered "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\Newtonsoft.Json.dll", but it didn't exist. (TaskId:17)
1>          Considered "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\Newtonsoft.Json.exe", but it didn't exist. (TaskId:17)
1>          For SearchPath "{TargetFrameworkDirectory}". (TaskId:17)
1>          Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Newtonsoft.Json.winmd", but it didn't exist. (TaskId:17)
1>          Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Newtonsoft.Json.dll", but it didn't exist. (TaskId:17)
1>          Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Newtonsoft.Json.exe", but it didn't exist. (TaskId:17)
1>          For SearchPath "{Registry:Software\Microsoft\.NETFramework,v4.0,AssemblyFoldersEx}". (TaskId:17)
1>          Considered AssemblyFoldersEx locations. (TaskId:17)
1>      Required by "CommonUtils". (TaskId:17)
1>      The ImageRuntimeVersion for this reference is "v4.0.30319". (TaskId:17)

But I don't see it on my computer, where the compilation fails

Final Update:

I gave up and reinstalled my whole system - it works now, however it doesn't answer the question where the wrong Newtonsoft.Json.dll came from and why it didn't show up in the GAC, I can finally again work on that project.

I'm actually quite disappointed, that it can't be as easy as in maven, where you can just delete one folder in order to make maven redownload all the libraries.

I have an image of the broken system on a VHD, so if anyone else comes up with a great solution, I can try it out in the VM.

解决方案

I had the same issue, and the solution was to delete the Newtonsoft.json.dll located in c:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.3\ref

This is described as a workaround in this Connect bug report.

Edit: Original bug report removed, possible new/related/same issue: https://connect.microsoft.com/VisualStudio/feedback/details/816985

这篇关于Visual Studio抛出“错误"消息.编译时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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