Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Antelope-IT opened this issue May 8, 2020 · 23 comments

Comments

@Antelope-IT
Copy link

Antelope-IT commented May 8, 2020

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: .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: .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 '.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: .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
@cartermp
Copy link

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.

@Antelope-IT
Copy link
Author

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.

@aintitfun
Copy link

same issue here!

@selfagency
Copy link

same!

@selfagency
Copy link

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.

@JoeRobich
Copy link
Member

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)

@cartermp
Copy link

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

@adenflorian
Copy link

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

@f00f
Copy link

f00f commented Nov 13, 2020

I got the same issue.

@LinoBarreca
Copy link

LinoBarreca commented Jan 13, 2021

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

@d0972058277
Copy link

same.

@fangpin
Copy link

fangpin commented Jun 18, 2021

got same issue, is there any update on this

@MrBaoquan
Copy link

same here, i reference a IWshRuntimeLibrary caused this issue

@0ptikGhost
Copy link

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?

@kimtaeyo
Copy link

Same issue here. Any fix?

@Bigous
Copy link

Bigous commented Nov 18, 2021

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?

@Xarkam
Copy link

Xarkam commented Dec 10, 2021

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.

@roa-nyx
Copy link

roa-nyx commented Jan 16, 2022

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.

@Irian-Adappty
Copy link

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

@Lumoryel
Copy link

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

@MarcosAlonsoVianney
Copy link

Still waiting for a solution...😢

@NikiPn
Copy link

NikiPn commented Oct 18, 2024

Same 😢

@JoeRobich
Copy link
Member

Closing as ComReferences are not supported on modern .NET. See dotnet/msbuild#3986 (comment)

@JoeRobich JoeRobich closed this as not planned Won't fix, can't repro, duplicate, stale Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests