Using Microsoft.Bcl.Async with Code Analysis causes errors

ⅰ亾dé卋堺 提交于 2019-11-30 03:44:46

As mentioned by Nicole, this occurs because Code Analysis/FxCop is enforcing that strong names including versions match exactly. This behavior makes sense for .NET Framework, until you start to factor in binding redirects (or other platforms such as Store, Phone & Silverlight which always allow later versions of an assembly to match an earlier version), which FxCop does not respect.

I wrote this original behavior in FxCop, and it was over optimizing for correctness vs real world. At the time, we didn't have an opt out other than via the App.Config. However, luckily after I left the team, some smart person on the team added one both via the command-line and within Visual Studio.

Via the command-line:

FxCopCmd.exe /assemblycomparemode:StrongNameIgnoringVersion ...

Via Visual Studio:

  1. Right-click on the project in Solution Explorer and choose Unload
  2. Right-click on the project in Solution Explorer and choose Edit
  3. Within the first <PropertyGroup> element, add the following: <CodeAnalysisAdditionalOptions> /assemblycomparemode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
  4. Right-click on the project in Solution Explorer, choose Reload saving the changes when prompted.

This will only work in Visual Studio 2012 and higher.

This happens because the versions of the dependencies declared in Bcl.Async assemblies don't match those available at analysis time. The simplest workaround is to adjust FxCop's AssemblyReferenceResolveMode as described at http://davesbox.com/archive/2008/06/14/reference-resolutions-changes-in-code-analysis-and-fxcop-part-2.aspx.

Having the same problem, and looking for a solution. The only mention I've found is in the comments of the bcl blog post - Microsoft.Bcl.Async is Now Stable (page 3 of comments) where Immo Landwerth's response to someone having the same issue is;

We're looking into it. At first glance it seems like a unification issue in the VS static code analysis feature (FxCop). We've contacted the owners of it. Unfortunately, I don't think there is a workaround other than disabling code analysis for those projects :-(

The response is dated 26th April 2013, whether there have been any developments since then.

So for now I guess the workarounds are:

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