22

This may seem as one of many similar questions, but I could not find the solution in other questions.

I will jump straight to the binary log:

enter image description here

And here is the respective subtree under the ResolveAssemblyReference task:

There was a conflict between "System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". "System.Runtime.CompilerServices.Unsafe, Version = 4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not. References which depend on "System.Runtime.CompilerServices.Unsafe, Version = 4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [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 "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 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 "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.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 "C:\Users\mkharitonov\.nuget\packages\system.memory\4.5.3\lib\netstandard2.0\System.Memory.dll". 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 "C:\xyz\tip\Tools\MSBuild\..\..\bin.link\System.Threading.Tasks.Extensions.dll". GrossPayEngineDataProvider C:\xyz\tip\Tools\MSBuild\..\..\bin.link\Pipelines.Sockets.Unofficial.dll Project file item includes which caused reference "C:\xyz\tip\Tools\MSBuild\..\..\bin.link\Pipelines.Sockets.Unofficial.dll". GrossPayEngineDataProvider References which depend on "System.Runtime.CompilerServices.Unsafe, Version = 4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\System.Runtime.CompilerServices.Unsafe.dll]. 

From which I conclude there are two versions of the System.Runtime.CompilerServices.Unsafe.dll at play:

  1. A NuGet package - C:\Users\mkharitonov.nuget\packages\system.runtime.compilerservices.unsafe\4.5.2\ref\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll
  2. C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\System.Runtime.CompilerServices.Unsafe.dll

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?

The project in question is just a library and hence does not have an app.config file. Also, AutoUnify == true so the ResolveAssemblyReference task should automatically resolve the conflict to the highest version, at least this is my interpretation of the documentation.

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 C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\System.Runtime.CompilerServices.Unsafe.dll ?

For the record:

  1. 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?
  2. None of my code makes direct reference to System.Runtime.CompilerServices.Unsafe, so all the dependencies listed by the ResolveAssemblyReference task must be transitive.
  3. I tried adding app.config 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 AutoGenerateBindingRedirects property. As I expected - it did not help.

How can I determine what is going on and how to fix it?

4
  • 1
    we are experiencing the same error. After we updated Visual Studio 19 to the latest version on the build server. Check: github.com/xamarin/xamarin-android/issues/4872 Commented Oct 21, 2020 at 13:01
  • My msbuild version is 16.7.0+b89cb5fde. I guess I have to upgrade to the latest version to verify. Commented Oct 21, 2020 at 13:50
  • I have the same problem with msbuild 16.9.0+57a23d249. Don't have an app.config file. Project does not reference that file directly, only indirectly. Correct version of file is already in output dir due to nuget restore a different project (a super project that hold all nuget packages). Even so, msbuild overwrite correct version of the file in output dir with an older version during _CopyFilesMarkedCopyLocal (from C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\System.Runtime.CompilerServices.Unsafe.dll). Annoying. Tried everything but no go. Commented Mar 22, 2021 at 22:20
  • For me this was the solution, to globally disable copy local (i put it in Directory.Build.targets): thomasfreudenberg.com/archive/2012/11/21/… Commented Mar 23, 2021 at 12:34

4 Answers 4

16

I have an update. On our side there was an entry in one of the app.config redirecting to the 4.0.6.0.

We have never seen the problem, because there was no 4.0.6.0 on the build machine.

But as we've updated Visual Studio to the newest version, msbuild somehow was copying it.

_CopyFilesMarkedCopyLocal: The File will be copied from "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\System.Runtime.CompilerServices.Unsafe.dll" in "D:\agent_03\_work\21\s\Release\System.Runtime.CompilerServices.Unsafe.dll". 

As soon we deleted the entry on the config file, the file was not copied anymore.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" /> </dependentAssembly> </assemblyBinding> 

Search for any specific entry on you app.configs. If you can't find it, i'm afraid you need to go through all your nuget dependencies till you find which one needs this specific version.

Cheers, Marco

Sign up to request clarification or add additional context in comments.

3 Comments

I have no such binding redirect. It still happens.
If you have mixed usage of .net framework and .net standard this might help you stackoverflow.com/a/59720475/4146066
This helped me also to solve a similar issue when using NUnit for testing.
4

I suddenly had the same error on building the solution. I restored a backup and tried a build. That worked again but after copying the updated code snippets the error came back. Updating the Unsafe.dll package, removing the references everywhere, updating Visual Studio etc did not help. It always restored the incorrect library again somehow.

By pure change I discovered the cause. It had to do with a Linq statement. Which looked something like this

MyList.ForEach(x => x.property = x.property.Replace("ABC", MyOtherList.Where(x => x.property == SomeValue).First().name))); 

This caused no errors in the Error List. But this line caused the library Unsafe.dll to be added to the project again and again. And failing the build. Changing the second Linq part x to y fixed all the issues.

MyList.ForEach(x => x.property = x.property.Replace("ABC", MyOtherList.Where(y => y.property == SomeValue).First().name))); 

Maybe this helps someone else because this simple issue cost me about 3 hours of extra work.

Comments

4

I ran into a similar issue with a solution. It turned out I had 3 different versions of this library somehow. The highest in use being 4.7.1 so I upgraded all of them and that fixed it. If you have a solution with multiple projects, use NuGet Package Manager to review this library in use in your other projects and see if that could be why it is putting this in the log

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
1

use NuGet and search for "System.Runtime.CompilerServices.Unsafe" on the project where is the warning, upgrade to the lastest version and it will solve it

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.