Assembly Binding Redirection and Code Analysis

Iain Galloway picture Iain Galloway · Oct 28, 2010 · Viewed 9.4k times · Source

I'm using DotNetOpenAuth (which references System.Web.Mvc version 1.0.0.0) in a Mvc 3.0.0.0 project in Visual Studio 2010.

I'm using assembly binding redirection as follows:-

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

Everything works fine, except code analysis which gives me the following errors:-

CA0001 : The following error was encountered while reading module X: Assembly reference cannot be resolved: System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

and

CA0058 : The referenced assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be found. This assembly is required for analysis and was referenced by: X.

Is there a way to get the code analysis tool to respect the assembly binding redirection?

Answer

peter_raven picture peter_raven · Mar 31, 2011

Just to supplement with a little more precise answer:

You need to either run FxCopCmd.exe with:

fxcopcmd.exe /assemblyCompareMode:StrongNameIgnoringVersion

or modify your Visual Studio project file for each build configuration's property group, like this:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  ...
  <CodeAnalysisAdditionalOptions>/assemblyCompareMode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
</PropertyGroup>