Postsharp OWIN版本不匹配。

5
我在项目中使用了PostSharp 4.2.22.0和Owin 3.0.1。编译时出现以下错误:
Unhandled exception (4.2.22.0, postsharp-net40-x86-srv.exe, CLR 4.0.30319.394271, Release): PostSharp.Sdk.CodeModel.AssemblyLoadException: 找不到程序集 'microsoft.owin.security, version=2.1.0.0, culture=neutral, publickeytoken=31bf3856ad364e35'。[版本不匹配]
但是PostSharp和Owin有什么关系呢?为什么Owin的版本对于PostSharp很重要呢?这两个是完全不同的包。

1个回答

9
通常,这个错误出现在引用一个旧版本的程序集并在您的web.config文件中使用绑定重定向的项目中。我猜您的web.config文件中有类似以下内容的代码:
<dependentAssembly>
  <assemblyIdentity name="microsoft.owin.security" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
  <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
</dependentAssembly>

默认情况下,PostSharp不会处理web.config/app.config文件。可通过将PostSharpHostConfigurationFile MSBuild属性设置为您的web.config文件的路径,强制PostSharp加载绑定重定向。

您可以通过在csproj文件中添加以下行来实现:

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

这个不便之处在于PostSharp 4.3中已经修复,不需要设置PostSharpHostConfigurationFile属性。但目前4.3还不是稳定版本。
编辑:代码已更新(缺少结束符'>')。

我已经拥有了属性组,但错误仍然发生。 - Murphybro2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接