Skip to content

EnableComHosting usage results in MSB4018 GenerateClsidMap task failure #52276

@riverar

Description

@riverar

Describe the bug

When <EnableComHosting> is set to True, compilation of a class library with GeneratedComInterface and GeneratedComClass attributes fails with an obscure error.

Things I checked:

  • There is no visible SYSLIB error emitted.
  • Tutorial documentation doesn't explicitly cover use of these attributes, it's not clear if they're supported or not

It appears COM hosting and source-generated COM is not supported but neither the docs or error messages say anything helpful.

To Reproduce

  1. git clone https://github.com/riverar/repro-807e6dbdca02
  2. dotnet build
  3. Observe error

Exceptions (if any)

The "GenerateClsidMap" task failed unexpectedly.
System.InvalidCastException: Specified cast is not valid.
   at System.Reflection.Throw.InvalidCast()
   at System.Reflection.Metadata.TypeReferenceHandle.op_Explicit(EntityHandle handle)
   at Microsoft.NET.HostModel.ComHost.ClsidMap.IsTargetAttribute(MetadataReader reader, CustomAttribute attribute, String targetNamespace, String targetName)
   at Microsoft.NET.HostModel.ComHost.ClsidMap.GetComVisibleAttribute(MetadataReader reader, CustomAttributeHandleCollection customAttributes)
   at Microsoft.NET.HostModel.ComHost.ClsidMap.<IsComVisible>g__IsComVisibleCore|9_0(TypeDefinition typeDefinition, <>c__DisplayClass9_0& )
   at Microsoft.NET.HostModel.ComHost.ClsidMap.IsComVisible(MetadataReader metadataReader, TypeDefinition definition, Boolean assemblyComVisible)
   at Microsoft.NET.HostModel.ComHost.ClsidMap.Create(MetadataReader metadataReader, String clsidMapPath)
   at Microsoft.NET.Build.Tasks.GenerateClsidMap.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

Further technical details

details of dotnet --info

.NET SDK: Version: 10.0.101 Commit: fad253f51b Workload version: 10.0.100-manifests.9f71effe MSBuild version: 18.0.6+fad253f51

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26220
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.101\

.NET workloads installed:
[ios]
Installation Source: VS 18.3.11312.210
Manifest Version: 26.1.10502/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.ios\26.1.10502\WorkloadManifest.json
Install Type: Msi

[maccatalyst]
Installation Source: VS 18.3.11312.210
Manifest Version: 26.1.10502/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.maccatalyst\26.1.10502\WorkloadManifest.json
Install Type: Msi

[android]
Installation Source: VS 18.3.11312.210
Manifest Version: 36.1.2/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.android\36.1.2\WorkloadManifest.json
Install Type: Msi

[maui-windows]
Installation Source: VS 18.3.11312.210
Manifest Version: 10.0.1/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.maui\10.0.1\WorkloadManifest.json
Install Type: Msi

Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.1
Architecture: x64
Commit: fad253f51b

.NET SDKs installed:
8.0.416 [C:\Program Files\dotnet\sdk]
10.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Microsoft Visual Studio Enterprise
Channel: Insiders
Version: Insiders [11312.210]

#4099 seems related but was closed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions