Resolving MSB3247 Warning: Analysis and Automated Handling of Same Dependent Assembly Version Conflicts

Dec 01, 2025 · Programming · 16 views · 7.8

Keywords: MSB3247 | .NET | MSBuild | Assembly Conflict | Binding Redirect

Abstract: This article provides an in-depth analysis of the common MSB3247 warning in .NET projects, which indicates conflicts between different versions of the same dependent assembly. By detailing the mechanism of MSBuild's ResolveAssemblyReferences task, it offers multiple practical solutions: adjusting MSBuild output verbosity to obtain specific conflict information, configuring automatic binding redirects, manually adding binding redirects to configuration files, and using tools like AsmSpy to quickly locate conflict sources. The article demonstrates how to identify and fix common assembly version conflicts such as SqlServerCe through concrete cases, helping developers fundamentally resolve such build issues.

Problem Background and Mechanism Analysis

During .NET project development, when compiling with MSBuild, developers often encounter the MSB3247 warning: "Found conflicts between different versions of the same dependent assembly." This warning indicates that the project contains conflicting references to different versions of the same assembly, which may lead to runtime exceptions or unpredictable behavior.

This warning is generated by MSBuild's ResolveAssemblyReferences task, which is responsible for resolving all assembly references in the project. When multiple projects or dependencies reference different versions of the same assembly, this warning is triggered. The ResolveAssemblyReferences task operates in two modes: when configured to generate binding redirects, it automatically handles version conflicts; when not configured, it produces the MSB3247 warning.

Detailed Diagnostic Methods

To gain detailed insight into specific version conflicts, it's essential to adjust MSBuild's output verbosity. In Visual Studio, this can be configured through the following steps:

  1. Open the Options dialog (Tools->Options...)
  2. Select the Projects and Solutions node in the left-hand tree, then choose Build and Run
  3. If this node doesn't appear, ensure the Show all settings checkbox at the bottom of the dialog is checked
  4. On the tools/options page that appears, set the MSBuild project build output verbosity level according to your Visual Studio version:
    • Use Diagnostics level for VS2012, VS2013, or VS2015
    • Use Detailed level for VS2010
    • Normal level suffices for VS2008 or older versions
  5. Rebuild the project and examine the output window for detailed information

After setting the verbosity level, look for messages related to the ResolveAssemblyReferences task in the output window. For example, you might see information similar to:

Target ResolveAssemblyReferences:
    Consider app.config remapping of assembly "System.Data.SqlServerCe, ..." 
        from Version "3.5.1.0" [H:\...\Debug\System.Data.SqlServerCe.dll] 
        to Version "9.0.242.0" [C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies\System.Data.SqlServerCe.dll]
        to solve conflict and get rid of warning.
    C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets : 
        warning MSB3247: Found conflicts between different versions of the same dependent assembly.

Solution 1: Automatic Binding Redirect Generation

The most straightforward solution is to configure MSBuild to automatically generate binding redirects. In Visual Studio, this can be enabled through the following steps:

  1. Open Project Properties (Alt+Enter)
  2. Select the Application tab
  3. Check the Auto-generate binding redirects checkbox

Alternatively, add the property manually by editing the project file: within the project's PropertyGroup element, add:

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

When automatic binding redirects are enabled, the ResolveAssemblyReferences task automatically generates configuration files in the output directory containing appropriate binding redirects, ensuring consistent assembly versions at runtime.

Solution 2: Manual Binding Redirect Addition

If you prefer more explicit control over binding redirects or don't want MSBuild to generate them automatically, you can manually add binding redirects to configuration files. Add the corresponding binding redirect configuration to the <runtime> node in the app.config or web.config file.

The MSBuild warning message typically provides suggested binding redirect XML code that can be copied and pasted directly into the configuration file. For example:

<dependentAssembly>
    <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="..." culture="neutral" />
    <bindingRedirect oldVersion="3.5.1.0" newVersion="9.0.242.0" />
</dependentAssembly>

Auxiliary Tool Usage

Beyond relying on MSBuild output, specialized tools can be used to quickly identify assembly reference conflicts. Mike Hadlow's AsmSpy is a practical console application that clearly lists reference relationships for each assembly.

AsmSpy output format appears as follows:

Reference: System.Net.Http.Formatting
        4.0.0.0 by Shared.MessageStack
        4.0.0.0 by System.Web.Http

Reference: System.Net.Http
        2.0.0.0 by Shared.MessageStack
        2.0.0.0 by System.Net.Http.Formatting
        4.0.0.0 by System.Net.Http.WebRequest
        2.0.0.0 by System.Web.Http.Common
        2.0.0.0 by System.Web.Http
        2.0.0.0 by System.Web.Http.WebHost

This formatted output makes identifying version conflicts simple and intuitive, significantly more efficient than manually checking each assembly's reference properties.

Practical Case Analysis

In real-world projects, SqlServerCe is a common source of version conflicts. For instance, a project might reference both version 3.5.1.0 and 9.0.242.0 of the System.Data.SqlServerCe assembly. After identifying specific conflicts through MSBuild's detailed output or AsmSpy tool, the following steps can be taken to resolve them:

  1. Identify the assembly referencing the older version
  2. Remove the reference to the older version
  3. Add the correct reference to the newer version
  4. Or configure appropriate binding redirects

Beyond checking assembly reference properties, you can also examine reference versions by opening project files with a text editor or use decompilation tools like .NET Reflector to deeply analyze assembly dependencies.

Best Practice Recommendations

To avoid MSB3247 warnings, it's recommended to follow these best practices during project development:

By systematically applying these methods and tools, developers can effectively identify, analyze, and resolve assembly version conflicts, ensuring stable project builds and runtime operations.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.