Search code examples
c#reference

C# Found conflicts... circular reference?


In my solution consisting of ~20 projects, one project gives this build warning:

9>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2364,5): warning MSB3277: Found conflicts between different versions of "System.Drawing" that could not be resolved.
9>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2364,5): warning MSB3277: There was a conflict between "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Drawing, Version=6.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
9>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2364,5): warning MSB3277:     "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Drawing, Version=6.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
9>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2364,5): warning MSB3277:     References which depend on "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Drawing.dll].
9>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2364,5): warning MSB3277:         C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Drawing.dll
9>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2364,5): warning MSB3277:           Project file item includes which caused reference "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Drawing.dll".
9>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2364,5): warning MSB3277:             System.Drawing
9>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2364,5): warning MSB3277:     References which depend on "System.Drawing, Version=6.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [].

The references that depend on System.Drawing v6.0.2.0 consist of other projects within the solution, but the project file referring to v4.0.0.0 seems to be itself. I cannot find any way to prevent this self-reference. Any suggestions are appreciated.


Solution

  • From the comments...

    I may have found a fix. I removed

    <dependentAssembly> 
       <assemblyIdentity name="System.Drawing" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> 
       <bindingRedirect oldVersion="0.0.0.0-6.0.2.0" newVersion="6.0.2.0" /> 
    </dependentAssembly>
    

    from the project's app.config file. Feels a little odd to not enforce the newer version, but somewhere within the project, an older version dependency is causing the conflict. Is it reasonable to remove this redirect?

    Thanks to @Tenatus for help generating ideas