AssemblyLoadException in PostSharp on release build

吃可爱长大的小学妹 提交于 2019-12-06 09:43:36
AlexD

This usually can happen when some of the 3-rd party libraries reference an older version of the assembly (Newtonsoft.Json in this case). The problem is solved by specifying a binding redirect in your web.config/app.config file.

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

However, you also need to tell PostSharp where to look for binding redirect configuration. You can do this by setting PostSharpHostConfigurationFile property in your *.csproj file:

<PropertyGroup>
  <PostSharpHostConfigurationFile>web.config</PostSharpHostConfigurationFile>
</PropertyGroup>

There's another similar question on SO (PostSharp AssemblyLoadException Autofac), and a relevant blog post.

Turns out that while the exception was coming from PostSharp the remedy was updating all the NuGet packages.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!