vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

Load C# project with a COM reference fails: "ResolveComReference" task could not be instantiated...

Open Antelope-IT opened this issue 4 years ago • 22 comments

Issue Description

Omnisharp fails to load a project with a COM reference "ResolveComReference" task could not be instantiated...

Steps to Reproduce

I don't know the precise steps to reproduce but the project is an electronjs application with C# dependencies which although part of the project are actually managed through VS with a VS solution file. The C# components are a mix of .net core, .net standard 2 and full framework 4.7.2 projects. All the projects load except one. The problematic project was added recently it has a COM reference to the Windows Scripting Host library which I suspect is the trigger for the issue (the presence of the com reference not the specific library) The whole project builds through a combination of MSBuild and Electron-Build - this succeeds ok, and the VS solution file also builds the C# components separately without issue.

Expected Behavior

All C# projects should be loaded without issue.

I'm not sure why its trying to instantiate the COM task with version 15.1 of the Microsoft.Build.Tasks.Core when the version in the registered MS Build instance would appear to be v 16.5 AFAIKS - but then I could be trying to compare the wrong version numbers.

Actual Behavior

The C# project with a Com reference fails with an 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, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Logs

OmniSharp log

Starting OmniSharp server at 08/05/2020, 11:00:23 Target: .sln

OmniSharp server started. Path: <Redacted>.vscode\extensions\ms-dotnettools.csharp-1.21.18.omnisharp\1.35.2-beta.8\OmniSharp.exe PID: 18824

Starting OmniSharp on Windows 6.2.9200.0 (x64) info: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet info: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 4 MSBuild instance(s) 1: Visual Studio Enterprise 2019 16.5.30011.22 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin" 2: Visual Studio Build Tools 2017 15.9.28307.1033 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin" 3: Visual Studio Enterprise 2017 15.9.28307.812 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin" 4: StandAlone 16.4 - "c:\Users<Redacted>.vscode\extensions\ms-dotnettools.csharp-1.21.18.omnisharp\1.35.2-beta.8.msbuild\Current\Bin" info: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: Visual Studio Enterprise 2019 16.5.30011.22 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin"

Loading project: <Redacted>.csproj fail: OmniSharp.MSBuild.ProjectLoader 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, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. fail: OmniSharp.MSBuild.ProjectLoader The "ResolveComReference" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name. [warn]: OmniSharp.MSBuild.ProjectManager Failed to load project file '<Redacted>.csproj'. c:<Redacted>.csproj C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2701,5): 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, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2701,5): Error: The "ResolveComReference" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.

Attempted to update project that is not loaded: <Redacted>.csproj

C# log

Getting latest OmniSharp version information Downloading package 'Latest OmniSharp Version Information' (1 KB).................... Done!

Environment information

VSCode version: 1.45.0 C# Extension: 1.21.18

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.201 Commit: b1768b4ae7

Runtime Environment: OS Name: Windows OS Version: 10.0.18363 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.201\

Host (useful for support): Version: 3.1.3 Commit: 4a9f85e9f8

.NET Core SDKs installed: 1.1.13 [C:\Program Files\dotnet\sdk] 1.1.14 [C:\Program Files\dotnet\sdk] 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.505 [C:\Program Files\dotnet\sdk] 2.1.508 [C:\Program Files\dotnet\sdk] 2.1.602 [C:\Program Files\dotnet\sdk] 2.1.604 [C:\Program Files\dotnet\sdk] 2.1.700 [C:\Program Files\dotnet\sdk] 2.1.701 [C:\Program Files\dotnet\sdk] 2.1.801 [C:\Program Files\dotnet\sdk] 2.1.802 [C:\Program Files\dotnet\sdk] 2.2.105 [C:\Program Files\dotnet\sdk] 3.1.201 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
beautify HookyQR 1.5.0
csharp ms-dotnettools 1.21.18
cucumberautocomplete alexkrechik 2.14.1
debugger-for-chrome msjsdiag 4.12.6
docomment k--kato 0.1.9
gitlens eamodio 10.2.1
html-css-class-completion Zignd 1.19.0
powershell ms-vscode 2020.4.0
vscode-docker ms-azuretools 1.1.0
vscode-eslint dbaeumer 2.1.5
vscode-icons vscode-icons-team 10.1.1
vscode-typescript-tslint-plugin ms-vscode 1.2.3

Antelope-IT avatar May 08 '20 10:05 Antelope-IT

Thanks @Antelope-IT - is this project sharable? Unfortunately, this is close to impossible to understand without the project to work with. That said, there are some problems with the OmniSharp project system that could be leading to it just failing to load this task.

cartermp avatar May 12 '20 23:05 cartermp

Unfortunately the original project isn't sharable, but I have managed to reproduce it with a bare minimum project - the code compiles in VS 2019 but simply loading the folder in VS Code results in the OmniSharp log below. I doubt the code runs (I haven't tried it) - its just enough to get the error to show.

`Starting OmniSharp server at 13/05/2020, 08:16:12 Target: c:\tmp\OmnisharpTest\OmniSharpComWrapperTest\OmniSharpComWrapperTest.sln

OmniSharp server started. Path: c:\Users\Access.vscode\extensions\ms-dotnettools.csharp-1.21.18.omnisharp\1.35.2-beta.33\OmniSharp.exe PID: 25568

Starting OmniSharp on Windows 6.2.9200.0 (x64) info: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet info: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 4 MSBuild instance(s) 1: Visual Studio Enterprise 2019 16.5.30011.22 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin" 2: Visual Studio Build Tools 2017 15.9.28307.1033 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin" 3: Visual Studio Enterprise 2017 15.9.28307.812 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin" 4: StandAlone 16.4 - "c:\Users\Access.vscode\extensions\ms-dotnettools.csharp-1.21.18.omnisharp\1.35.2-beta.33.msbuild\Current\Bin" info: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: Visual Studio Enterprise 2019 16.5.30011.22 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin" info: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in 'c:\tmp\OmnisharpTest\OmniSharpComWrapperTest'. info: OmniSharp.Cake.CakeProjectSystem Could not find any Cake files info: OmniSharp.MSBuild.ProjectSystem Detecting projects in 'c:\tmp\OmnisharpTest\OmniSharpComWrapperTest\OmniSharpComWrapperTest.sln'. info: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\tmp\OmnisharpTest\OmniSharpComWrapperTest\ComWrapper\ComWrapper.csproj' info: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in 'c:\tmp\OmnisharpTest\OmniSharpComWrapperTest'. info: OmniSharp.Script.ScriptProjectSystem Could not find any CSX files info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 info: OmniSharp.MSBuild.ProjectManager Loading project: c:\tmp\OmnisharpTest\OmniSharpComWrapperTest\ComWrapper\ComWrapper.csproj info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100 info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110 info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140 info: OmniSharp.WorkspaceInitializer Configuration finished. info: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location 'c:\tmp\OmnisharpTest\OmniSharpComWrapperTest' on host 26920. fail: OmniSharp.MSBuild.ProjectLoader 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, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. fail: OmniSharp.MSBuild.ProjectLoader The "ResolveComReference" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name. [warn]: OmniSharp.MSBuild.ProjectManager Failed to load project file 'c:\tmp\OmnisharpTest\OmniSharpComWrapperTest\ComWrapper\ComWrapper.csproj'. c:\tmp\OmnisharpTest\OmniSharpComWrapperTest\ComWrapper\ComWrapper.csproj C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2701,5): 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, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2701,5): Error: The "ResolveComReference" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.

Attempted to update project that is not loaded: c:\tmp\OmnisharpTest\OmniSharpComWrapperTest\ComWrapper\ComWrapper.csproj ` Please see attached:

OmnisharpTest.zip

Hope this helps, if you need anything more then please come back to me.

Antelope-IT avatar May 13 '20 07:05 Antelope-IT

same issue here!

aintitfun avatar May 20 '20 15:05 aintitfun

same!

selfagency avatar Aug 10 '20 14:08 selfagency

what i notice about this is that Microsoft.Build, Version=15.1.0.0 doesn't actually exist in nuget. it goes from 15.1.0-preview to 15.1.1.548. wondering if that has anything to do with it.

selfagency avatar Aug 10 '20 14:08 selfagency

what i notice about this is that Microsoft.Build, Version=15.1.0.0 doesn't actually exist in nuget. it goes from 15.1.0-preview to 15.1.1.548. wondering if that has anything to do with it.

The version of MSBuild is locked to 15.1.0.0, however the FileVersion represent the true version of the assembly. (See comment)

JoeRobich avatar Aug 10 '20 14:08 JoeRobich

Thanks for the update. I can reproduce this with the project you added. This will need more investigation, sadly.

cartermp avatar Sep 23 '20 01:09 cartermp

Here's another sln that recreates the issue: https://github.com/AsoboStudio/FlightSim-glTF-exporter/tree/master/3ds%20Max

adenflorian avatar Oct 03 '20 01:10 adenflorian

I got the same issue.

f00f avatar Nov 13 '20 08:11 f00f

same here. I think it's more a microsoft problem (in the targets file)

LinoBarreca avatar Jan 13 '21 11:01 LinoBarreca

same.

d0972058277 avatar Mar 04 '21 17:03 d0972058277

got same issue, is there any update on this

fangpin avatar Jun 18 '21 07:06 fangpin

same here, i reference a IWshRuntimeLibrary caused this issue

MrBaoquan avatar Aug 13 '21 05:08 MrBaoquan

https://stackoverflow.com/a/44120849 says:

COM references are not supported by the .net core version of MSBuild

OmniSharp is built with the .NET Core SDK, right?

0ptikGhost avatar Sep 13 '21 20:09 0ptikGhost

Same issue here. Any fix?

kimtaeyo avatar Nov 13 '21 00:11 kimtaeyo

Just to help with the diagnostcs: here is a repository where it's happening: Bigous/MarketMonitor. It refers to a MSBuild version that is not installed in my system (15.1.0.0) image In my system the available MSBuild is 17.0.0.52104 image Opening the solution in VS2022 works flawlessly.

But I think the problem is the Microsoft.Build.Tasks.Core can't refers/open the COM reference.

Could you fallback to the msbuild instead of dotnet build for that task when you find that we are in Windows?

Bigous avatar Nov 18 '21 21:11 Bigous

I have the same problem:

C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2929,5): Error: Unable to instantiate task "ResolveComReference" from "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The specified file can not be found.
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2929,5): Error: Task  "ResolveComReference"was declared or used incorrectly, or failed during build. Check the spelling of the task and assembly name.

And stranger still, it breaks the UI of VSCode. Once Omnisharp crash, I lose the folding icons in the code editor part.

Xarkam avatar Dec 10 '21 15:12 Xarkam

Same issue here trying to add the following COMReference to Excel Interop.

  <ItemGroup>
    <COMReference Include="Microsoft.Office.Interop.Excel">
      <WrapperTool>tlbimp</WrapperTool>
      <VersionMinor>9</VersionMinor>
      <VersionMajor>1</VersionMajor>
      <Guid>00020813-0000-0000-c000-000000000046</Guid>
      <Lcid>0</Lcid>
      <Isolated>false</Isolated>
      <EmbedInteropTypes>true</EmbedInteropTypes>
    </COMReference>
  </ItemGroup>

Without this reference Omnisharp is happy.

roa-nyx avatar Jan 16 '22 04:01 roa-nyx

Same here suffering from this connecting remotely to my virtual machine Windows 10 on host Linux Mint

Irian-Adappty avatar Dec 19 '22 20:12 Irian-Adappty

Same problem. Still no fix after 3 years ? :(

Lumoryel avatar Oct 19 '23 08:10 Lumoryel

Still waiting for a solution...😢

MarcosAlonsoVianney avatar Jan 19 '24 15:01 MarcosAlonsoVianney