Azure Service Fabric 和 Newtonsoft.Json 兼容性问题

Azure Service Fabric and Newtonsoft.Json compability issues

我创建了一个新的 Service Fabric 应用程序来使用 Owin 自托管来托管 WebAPI 服务。

我将服务项目的所有 nuget 包更新到最新版本,现在当我尝试启动应用程序时出现以下错误:

Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

已在 App.config 中正确设置绑定重定向以重定向到最新版本的 Newtonsoft.Json。

      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
      </dependentAssembly>

我需要更新到最新版本的原因是由于其他依赖于较新版本的 Owin 和 Newtonsoft.Json。

这是 Service Fabric 结合 Owin 的一些已知限制吗?

您的一个项目正在使用较低版本的 Newtonsoft.Json 库。为确保您的所有项目(在整个解决方案内)都拥有正确的版本,请右键单击解决方案(在解决方案资源管理器 window 内)并 select 管理 Nuget 包。由于您在解决方案范围内,您会在其他常用选项卡(浏览、安装、更新)旁边看到一个 "Consolidate" 选项卡。 Select 包 Newtonsoft.Json,您将看到每个项目中安装的版本。确保每个项目使用相同的版本。