Yve*_* M. 81 assembly-resolution odata asp.net-mvc-4 asp.net-web-api
安装Microsoft ASP.NET Web API OData包5.0.0-rc1预发布后,我最终得到以下异常:
无法加载文件或程序集'System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)
我的MVC 4项目是全新的,非常小,没什么特别之处.我的目标是.NET framework 4.5
我需要这个nuget包来使用Delta类实现PATCH (当我使用包的版本4.0.0.0时,Delta类不起作用).
我该如何解决这个问题?
在GAC中,我有System.Web.Http的5.0.0.0版
gacutil -l System.Web.Http全局程序集缓存包含以下程序集:System.Web.Http,Version = 5.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35,processorArchitecture = MSIL
在Visual Studio中,当我浏览程序集时,System.Web.Http的给定版本是4.0.0.0(为什么?)
在我的项目中,对System.Web.Http的引用
我试图在Web.config中将redirect v 4.0.0.0绑定到5.0.0.0
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="4.0.0.0-4.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
但它给了我另一个例外:
通过方法'System.Web.Http.GlobalConfiguration..cctor()'尝试访问字段'System.Web.Http.GlobalConfiguration.CS $ <> 9__CachedAnonymousMethodDelegate2'失败.
我想v 4.0.0.0确实需要被核心Web Api引擎使用.
代码分析错误无法在MVC4 Web API中 加载文件或程序集'System.Net.Http,Version = 2.0.0.0无法在MVC4 Web API中加载文件或程序集'System.Net.Http,Version = 2.0.0.0
Jay*_*ass 164
Visual Studio 2013有一个新功能来处理这个问题.构建应用程序时,您应该看到有关正在引用的程序集的不同版本的警告.双击警告以将程序集绑定重定向添加到web.config.
有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/2fc472t2.aspx.
jeff.eynon在下面说明你需要检查web.config(如果使用TFS源代码控制)让VS自动编辑文件.谢谢你的提示!
Yve*_* M. 39
我通过使用nuget将WebApi包升级到预发布版本来实现它:
PM> Microsoft.AspNet.WebApi -Pre
Run Code Online (Sandbox Code Playgroud)
为了使用最新版本的WebApi强制项目,需要对根Web.config进行一些修改:
1)网页版本从2.0.0.0到3.0.0.0
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
2)为System.Web.Http和System.Net.Http.Formatting绑定重定向到5.0.0.0
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
我想就是这样
PS:解决方案受到WebAPI OData 5.0 Beta的高度启发- 访问GlobalConfiguration会引发安全性错误
Kev*_*che 11
当我尝试从项目模板更新热毛巾项目时,以及在2013年10月23日创建一个空项目并通过nuget在VS 2012中安装HotTowel时,我遇到了这个问题.
为了解决这个问题,我通过Nuget将Web Api Web Host和Web API软件包更新到5.0,目前是NuGet中的当前版本(2013年10月23日).
然后我添加了绑定指令:
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)
Bro*_*nek 11
我遇到了同样的问题,我通过将以下libs的CopyLocal设置为true来解决它:
System.Web.Http.dll
System.Web.Http.WebHost.dll
System.Net.Http.Formatting.dll
我必须补充一点,我使用MVC4和NET 4
或者您可以从NuGet Package Manager Console执行此操作
Install-Package Microsoft.AspNet.WebApi -Version 5.0.0
Run Code Online (Sandbox Code Playgroud)
然后,您将能够添加对System.Web.Http.WebHost 5.0的引用
归档时间: |
|
查看次数: |
152643 次 |
最近记录: |