为了在 Mono 中部署我的项目,我已将其降级为 .Net 4.0,就像我对我引用的库 (CommonUtils) 所做的那样。但是,我仍然遇到以下异常:
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".
我尝试解决的问题:
这些都没有帮助。
这两个项目都设置为编译为 .Net 4.0。引用是通过将已编译的程序集 CommonUtils 复制到“ExternalLibraries”文件夹中,因为此 DLL 也用于其他项目。
右键单击 Newtonsoft.Json.dll - 它与 CommonUtils 一起移动到 bin 文件夹 - 在详细信息/文件描述中显示:Json。 .NET 4.0
我很确定我拥有适用于 .net 4.0 的所有内容,并且 Visual Studio 还允许我添加库并支持我自动完成,只是编译会抛出上述警告。作为警告的结果,我突然得到异常,CommonUtils 引用的类型都不存在
The type of namespace name 'CommonUtils' could not be found (are you missing a using directive or an assembly reference?)
我还可以尝试什么来完成这项工作?
PS:几年前我遇到过类似的问题,一个旧程序集用于编译,并通过从头开始设置 Windows 和 visual studio 来“解决”它,但我只是不想这样做时间。
更新:
它可以在另一台计算机上运行:我已经通过 USB 棒将文件夹结构带到另一台具有相同操作系统 (Windows 8.1) 和相同 Visual Studio 2013 的计算机上 - 据我所知,两台计算机都应该具有所有已安装更新 - 并且可以正常工作。
将带有成功编译项目的 USB 内存棒放回我的 PC - 我仍然遇到相同的错误。
(我明白,这意味着两台计算机不可能安装相同的所有东西,但我不知道如何找到不同之处,也许可以通过这种方式提示一些问题?)
更新 2:
Process explorer 没有太大帮助,但是当我用诊断日志编译所有内容时,我想我得到了关键提示:
...
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)
...
但是,我在另一台运行构建的计算机上也收到了完全相同的消息。
此外,两台计算机都在开头显示这一行:
Skipping NuGet package Newtonsoft.Json 6.0.3 since it is already installed.
在这种情况下,installed 是什么意思?那NuGet下载了吗?还是在 GAC 的某处,但我找不到? (见评论)
在编译工作的机器上,我还得到了这个输出:
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)
但是在我的电脑上没有看到,编译失败
最终更新:
我放弃并重新安装了我的整个系统 - 它现在可以工作了,但是它没有回答错误的 Newtonsoft.Json.dll 来自哪里以及为什么它没有出现在 GAC 中的问题,我终于可以再次在那个项目上工作。
我真的很失望,它不像在 maven 中那么简单,你可以只删除一个文件夹以使 maven 重新下载所有库。
我在 VHD 上有一个损坏系统的图像,所以如果其他人提出了一个很好的解决方案,我可以在 VM 中尝试一下。
最佳答案
我有同样的问题,解决方案是删除位于 c:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2 的 Newtonsoft.json.dll .3\ref
这在 Connect bug report 中被描述为解决方法.
编辑:删除了原始错误报告,可能是新的/相关的/相同的问题:https://connect.microsoft.com/VisualStudio/feedback/details/816985
关于c# - Visual Studio 抛出 "wrong"编译时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24922637/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我正在使用这个:4.times{|i|assert_not_equal("content#{i+2}".constantize,object.first_content)}我之前声明过局部变量content1content2content3content4content5我得到的错误NameError:wrongconstantnamecontent2这个错误是什么意思?我很确定我想要content2=\ 最佳答案 你必须用一个大字母来调用ruby常量:Content2而不是content2。Aconstantnamestart
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在学习Rails,并阅读了关于乐观锁的内容。我已将类型为integer的lock_version列添加到我的articles表中。但现在每当我第一次尝试更新记录时,我都会收到StaleObjectError异常。这是我的迁移:classAddLockVersionToArticle当我尝试通过Rails控制台更新文章时:article=Article.first=>#我这样做:article.title="newtitle"article.save我明白了:(0.3ms)begintransaction(0.3ms)UPDATE"articles"SET"title"='dwdwd
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub