title: Found conflicts between different versions of "System.Runtime.CompilerServices.Unsafe" that could not be resolved
body: <p>This may seem as one of many similar questions, but I could not find the solution in other questions.</p>
  <p>I will jump straight to the binary log:</p>
  <p><a href="https://i.stack.imgur.com/5BNlX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5BNlX.png" alt="enter image description here" /></a></p>
  <p>And here is the respective subtree under the <code>ResolveAssemblyReference</code> task:</p>
  <pre><code>There was a conflict between &quot;System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot; and &quot;System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot;.
      &quot;System.Runtime.CompilerServices.Unsafe, Version = 4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot; was chosen because it was primary and &quot;System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot; was not.
      References which depend on &quot;System.Runtime.CompilerServices.Unsafe, Version = 4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot; [C:\Users\mkharitonov\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.2\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll].
      C:\Users\mkharitonov\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.2\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll
            Project file item includes which caused reference &quot;C:\Users\mkharitonov\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.2\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll&quot;.
              C:\Users\mkharitonov\.nuget\packages\system.runtime.compilerservices.unsafe\4.5.2\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll
          C:\Users\mkharitonov\.nuget\packages\microsoft.extensions.primitives\2.0.0\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll
            Project file item includes which caused reference &quot;C:\Users\mkharitonov\.nuget\packages\microsoft.extensions.primitives\2.0.0\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll&quot;.
              C:\Users\mkharitonov\.nuget\packages\microsoft.extensions.primitives\2.0.0\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll
              C:\Users\mkharitonov\.nuget\packages\microsoft.extensions.caching.abstractions\2.0.0\lib\netstandard2.0\Microsoft.Extensions.Caching.Abstractions.dll
              xyz.Common
              C:\xyz\tip\bin.link\xyz.Web.Framework.dll
              C:\xyz\tip\bin.link\xyz.Web.Platform.dll
              AccrualEngine
              DataProcessor
              xyz.BusinessAPI.Core
              xyz.DataManager
              DataSvc
              xyz.Data
              xyz.HtmlPlatform
              xyz.BusinessAPI
              DeviceServices
              GrossPayEngineDataProvider
              MultiApprovalProcessor
              Payroll.Core.Data
              PunchStatusReconciliationEngine
              RateEngine2
              RateEngineDataProviderServer
              RuleEngine
              RuleEngineDataProvider
              RuleEngineHelper
              SharpTop.Common.Security.MemberSession
              SharpTop.DB.DL
              WorkTimeCalculationEngine
              C:\Users\mkharitonov\.nuget\packages\microsoft.extensions.caching.memory\2.0.0\lib\netstandard2.0\Microsoft.Extensions.Caching.Memory.dll
              C:\Users\mkharitonov\.nuget\packages\microsoft.extensions.options\2.0.0\lib\netstandard2.0\Microsoft.Extensions.Options.dll
          C:\Users\mkharitonov\.nuget\packages\system.memory\4.5.3\lib\netstandard2.0\System.Memory.dll
            Project file item includes which caused reference &quot;C:\Users\mkharitonov\.nuget\packages\system.memory\4.5.3\lib\netstandard2.0\System.Memory.dll&quot;.
              C:\Users\mkharitonov\.nuget\packages\system.memory\4.5.3\lib\netstandard2.0\System.Memory.dll
              C:\Users\mkharitonov\.nuget\packages\system.diagnostics.diagnosticsource\4.6.0\lib\net46\System.Diagnostics.DiagnosticSource.dll
              C:\Users\mkharitonov\.nuget\packages\microsoft.applicationinsights\2.10.0\lib\net46\Microsoft.ApplicationInsights.dll
              C:\Users\mkharitonov\.nuget\packages\xyz.engine.core.common\1.0.20260.1\lib\netstandard2.0\xyz.Engine.Core.Common.dll
              xyz.Common
              C:\xyz\tip\bin.link\xyz.Web.Framework.dll
              C:\xyz\tip\bin.link\xyz.Web.Platform.dll
              AccrualEngine
              DataProcessor
              xyz.BusinessAPI.Core
              xyz.DataManager
              DataSvc
              xyz.Data
              xyz.HtmlPlatform
              xyz.BusinessAPI
              DeviceServices
              GrossPayEngineDataProvider
              MultiApprovalProcessor
              Payroll.Core.Data
              PunchStatusReconciliationEngine
              RateEngine2
              RateEngineDataProviderServer
              RuleEngine
              RuleEngineDataProvider
              RuleEngineHelper
              SharpTop.Common.Security.MemberSession
              SharpTop.DB.DL
              WorkTimeCalculationEngine
          C:\xyz\tip\Tools\MSBuild\..\..\bin.link\System.Threading.Tasks.Extensions.dll
            Project file item includes which caused reference &quot;C:\xyz\tip\Tools\MSBuild\..\..\bin.link\System.Threading.Tasks.Extensions.dll&quot;.
              GrossPayEngineDataProvider
          C:\xyz\tip\Tools\MSBuild\..\..\bin.link\Pipelines.Sockets.Unofficial.dll
            Project file item includes which caused reference &quot;C:\xyz\tip\Tools\MSBuild\..\..\bin.link\Pipelines.Sockets.Unofficial.dll&quot;.
              GrossPayEngineDataProvider
      References which depend on &quot;System.Runtime.CompilerServices.Unsafe, Version = 4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot; [C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\System.Runtime.CompilerServices.Unsafe.dll].
  </code></pre>
  <p>From which I conclude there are two versions of the <code>System.Runtime.CompilerServices.Unsafe.dll</code> at play:</p>
  <ol>
  <li>A NuGet package - <strong>C:\Users\mkharitonov.nuget\packages\system.runtime.compilerservices.unsafe\4.5.2\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</strong></li>
  <li><strong>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\System.Runtime.CompilerServices.Unsafe.dll</strong></li>
  </ol>
  <p>The binary log goes to a great detail showing which assemblies depend on the NuGet package, but it shows none for the second reference. Which is weird, because then the question is - why the second version is considered in the first place?</p>
  <p>The project in question is just a library and hence does not have an app.config file. Also, <code>AutoUnify == true</code> so the <code>ResolveAssemblyReference</code> task should automatically resolve the conflict to the highest version, at least this is my interpretation of the <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.build.tasks.resolveassemblyreference.autounify?view=msbuild-16-netcore" rel="noreferrer">documentation</a>.</p>
  <p>So, I am puzzled. I know that the warning is minor and can be ignored, but I want to understand the nature of it. What is causing it if apparently all the dependencies rely on the NuGet package. Or maybe the task does not output certain kind of dependencies and leaves it up to me to investigate what depends on <strong>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\System.Runtime.CompilerServices.Unsafe.dll</strong> ?</p>
  <p>For the record:</p>
  <ol>
  <li>the assembly version of the NuGet package is 4.0.4.1 and that of the second version is 4.0.6.0, so should not all resolve to the highest version, i.e. the second version?</li>
  <li>None of my code makes direct reference to System.Runtime.CompilerServices.Unsafe, so all the dependencies listed by the <code>ResolveAssemblyReference</code> task must be transitive.</li>
  <li>I tried adding <strong>app.config</strong> file to the project in question with the binding redirects, even though there supposed to be no need for that due to the presence of the <code>AutoGenerateBindingRedirects</code> property. As I expected - it did not help.</li>
  </ol>
  <p>How can I determine what is going on and how to fix it?</p>