我收到错误:
Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. Manifest definition does not match the assembly reference.
将 WebApi Controller 类添加到我的 ASP.NET MVC 项目后。我的项目中也有 SignalR。两者都使用 Newtonsoft.Json,但似乎它们没有引用相同的版本。
SignalR 使用并与 6.0.8 版本配合使用,而错误告诉我 MapHttpRoute :
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
RouteTable.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
}
尝试加载4.5版本。
我读了这篇文章SignalR & WebApi - colliding Newtonsoft.Json references
但我不知道如何告诉 webapi 指向 6.0.8 版本。
最佳答案
您可以使用 AssemblyBinding 重定向到已安装的 Newtonsoft.Json 程序集。只需添加到您的 Web.config
</configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.8" newVersion="6.0.8" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
这会将所有错误版本的调用重定向到您安装的版本 6.0.8
关于c# - Newtonsoft.Json DLL 版本与 signalR + WEBAPI 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39794088/