The ResolveComReference task could not be instantiated from Microsoft.Build.Tasks.Core

Viewed 1222

I'm using MsBuild 15.0 APIs to build our own projects. Because of this version of MsBuild doesn't exist in GAC, I had to use library which is called MSBuildLocator to load assemblies of MsBuild. When I want to build projects with COMReferences I get below error:

The "ResolveComReference" task could not be instantiated from "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Could not load file or assembly 'Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) The "ResolveComReference" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.

and this is my assembly binding logs

Microsoft.Build.dll

LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\tfsbuild\Desktop\MSBuildTester\MSBuildTester\bin\Debug\MSBuildTester.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 15.1.0.0. LOG: Post-policy reference: Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a LOG: GAC Lookup was unsuccessful. LOG: Attempting download of new URL file:///C:/Users/tfsbuild/Desktop/MSBuildTester/MSBuildTester/bin/Debug/Microsoft.Build.DLL. LOG: Attempting download of new URL file:///C:/Users/tfsbuild/Desktop/MSBuildTester/MSBuildTester/bin/Debug/Microsoft.Build/Microsoft.Build.DLL. LOG: Attempting download of new URL file:///C:/Users/tfsbuild/Desktop/MSBuildTester/MSBuildTester/bin/Debug/Microsoft.Build.EXE. LOG: Attempting download of new URL file:///C:/Users/tfsbuild/Desktop/MSBuildTester/MSBuildTester/bin/Debug/Microsoft.Build/Microsoft.Build.EXE. LOG: All probing URLs attempted and failed.

Microsoft.Build.Tasks.Core.dll

LOG: This bind starts in LoadFrom load context. WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load(). LOG: Using application configuration file: C:\Users\tfsbuild\Desktop\MSBuildTester\MSBuildTester\bin\Debug\MSBuildTester.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Redirect found in application configuration file: 15.1.0.0 redirected to 15.1.0.0. LOG: Post-policy reference: Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a LOG: GAC Lookup was unsuccessful. LOG: Attempting download of new URL file:///C:/Users/tfsbuild/Desktop/MSBuildTester/MSBuildTester/bin/Debug/Microsoft.Build.Tasks.Core.DLL. LOG: Attempting download of new URL file:///C:/Users/tfsbuild/Desktop/MSBuildTester/MSBuildTester/bin/Debug/Microsoft.Build.Tasks.Core/Microsoft.Build.Tasks.Core.DLL. LOG: Attempting download of new URL file:///C:/Users/tfsbuild/Desktop/MSBuildTester/MSBuildTester/bin/Debug/Microsoft.Build.Tasks.Core.EXE. LOG: Attempting download of new URL file:///C:/Users/tfsbuild/Desktop/MSBuildTester/MSBuildTester/bin/Debug/Microsoft.Build.Tasks.Core/Microsoft.Build.Tasks.Core.EXE. LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/Microsoft.Build.Tasks.Core.DLL. LOG: Assembly download was successful. Attempting setup of file: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Build.Tasks.Core.dll LOG: Entering run-from-source setup phase. LOG: Assembly Name is: Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a LOG: Where-ref bind Codebase does not match what is found in default context. Keep the result in LoadFrom context. LOG: Binding succeeds. Returns assembly from C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Build.Tasks.Core.dll. LOG: Assembly is loaded in LoadFrom load context.

How can I resolve that ?!!

1 Answers

I just got this in the latest build of VS 2019. All I had done since it complied successfully the other day was to add a few lines of trivial code - no new functions. I switched from Debug mode to release and built the solution - no change. I switched back to Debug and the problem went away! NO coding changes.

Then when I went to actually debug the project, the error came back!

It subsequently turned out that Visual Studio was confused. I uninstalled and re-installed it and the problem went away.

Related