I'm trying to use Microsoft.Bcl.Async
and Code Analysis, but when I run Code Analysis I get one or more errors.
I'm using Visual Studio 2012 with Update 2.
This is easy for me to reproduce:
.Net 4
.References
then select Manage NuGet Packages...
Online
and type async
into the Search Online
box.Async for .Net Framework 4 ...
. Click Install
and accept all questions.Main()
a line that says: TaskEx.Delay(1000);
and a using System.Threading.Tasks;
Enable Code Analysis on Build
.I get two Code Analysis errors:
CA0052 Error Running Code Analysis CA0052 : No targets were selected. [Errors and Warnings] (Global)
CA0055 Error Running Code Analysis CA0055 : Could not load ConsoleApplication2.exe. The following error was encountered while reading module 'ConsoleApplication2': Could not resolve member reference: [Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]System.Threading.Tasks.TaskEx::Delay. [Errors and Warnings] (Global)
I get different code analysis errors for other test programs. A basic Windows Forms app I tried gives me:
CA0001 Error Running Code Analysis CA0001 : The following error was encountered while reading module 'AsyncForNet4': Could not resolve member reference: [Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]System.Threading.Tasks.TaskEx::Delay. [Errors and Warnings] (Global)
Two questions:
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:
<PropertyGroup>
element, add the following: <CodeAnalysisAdditionalOptions> /assemblycomparemode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
This will only work in Visual Studio 2012 and higher.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With