Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly Binding Redirection and Code Analysis

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?

like image 884
Iain Galloway Avatar asked Oct 28 '10 12:10

Iain Galloway


People also ask

What is an assembly Binding redirect?

1 or a later version, the app uses automatic binding redirection. This means that if two components reference different versions of the same strong-named assembly, the runtime automatically adds a binding redirection to the newer version of the assembly in the output app configuration (app.

What is Assemblybinding?

<dependentAssembly> <assemblyIdentity name="FooBar" publicKeyToken="32ab4ba45e0a69a1" culture="en-us" /> <bindingRedirect oldVersion="7.0.0.0" newVersion="8.0.0.0" /> </dependentAssembly>

How do I stop redirect binding?

Right-click the project in Solution Explorer and select Properties. On the Application page, uncheck the Auto-generate binding redirects option. If you don't see the option, you'll need to manually disable the feature in the project file. Press Ctrl + S to save the change.

What does auto generate binding redirects do?

1 use automatic binding redirection. This means that if two components reference different versions of the same strong-named assembly, the runtime automatically adds a binding redirection to the newer version of the assembly in the output app configuration (app.


2 Answers

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> 
like image 99
peter_raven Avatar answered Oct 09 '22 09:10

peter_raven


See http://davesbox.com/archive/2008/06/10/reference-resolution-changes-in-code-analysis-and-fxcop-part-1.aspx and http://davesbox.com/archive/2008/06/14/reference-resolutions-changes-in-code-analysis-and-fxcop-part-2.aspx for a bit of background information.

In VS2010/FxCop 10.0, there's a new /assemblyCompareMode command line switch for fxcopcmd.exe that allows you to specify the comparison mode without mucking about with the .config file. You can specify this in you VS project by using the CodeAnalysisAdditionalOptions MSBuild property.

like image 34
Nicole Calinoiu Avatar answered Oct 09 '22 10:10

Nicole Calinoiu