gpt4 book ai didi

c# - 冲突 Newtonsoft.Json DLL 版本与 signalR + WEBAPI

转载 作者:行者123 更新时间:2023-11-30 21:45:52 26 4
gpt4 key购买 nike

我得到错误:

Could not load file or assembly 'Newtonsoft.Json' or one of itsdependencies. Manifest definition does not match the assemblyreference.

将 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com