Skip to content

ComInterfaceGenerator failed to generate source when two base COM interfaces in another assembly have methods of the same name #122708

Closed

Description

@LideLinusZhang

Description

Consider the following case, where two COM interfaces of one assembly each inherit one of the two disjoint base COM interfaces of another assembly. The two base interfaces happen have methods of the same name.

In Assembly1

using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;

namespace Assembly1
{
    [GeneratedComInterface]
    [Guid("2d3b434a-9119-45c6-9f40-1d35bb38d494")]
    public partial interface IInterface1
    {
        double MyMethod();
    }

    [GeneratedComInterface]
    [Guid("5ef8dd8a-6c27-4724-8645-4406a4e45a8d")]
    public partial interface IInterface2
    {
        int MyMethod();
    }
}

And in Assembly2

using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;

namespace Assembly2
{
    [GeneratedComInterface]
    [Guid("b7c27add-cbc3-41c6-9e15-ddaf167c21a9")]
    public partial interface IInterface3 : Assembly1.IInterface1;

    [GeneratedComInterface]
    [Guid("5193a610-67dd-46b4-9f8c-238047c97ffb")]
    public partial interface IInterface4 : Assembly1.IInterface2;
}

Compile Assembly2, and ComInterfaceGenerator fails to generate source.

Reproduction Steps

See Description.

Expected behavior

The code should compile with ComInterfaceGenerator generating source for COM interop.

Actual behavior

Compiling Assembly2 yields the following warning

CSC : warning CS8785: Generator 'ComInterfaceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'An item with the same key has already been added. Key: ComMethodInfo { Syntax = , MethodName = MyMethod, Attributes = SequenceEqualImmutableArray { Array = System.Collections.Immutable.ImmutableArray`1[Microsoft.Interop.AttributeInfo], Comparer = System.Collections.Generic.GenericEqualityComparer`1[Microsoft.Interop.AttributeInfo], Length = 0 }, IsUserDefinedShadowingMethod = False }'.

indicating that ComInterfaceGenerator has failed to generate source for COM interop.

This is also true even if you put IInterface1 and IInterface2 into two different namespaces.

Regression?

Not sure, but should affect .NET 9 also.

Known Workarounds

Putting IInterface1 and IInterface2 in two separate assemblies.

Configuration

  • .NET Version: 10.0.101
  • OS: Windows 11 Enterprise 24H2 Build 26100.7171
  • Architecture: x64

Other information

May be related to #111890

Activity

  1. added
    untriaged
    on Dec 22, 2025
  2. dotnet-policy-service commented on Dec 22, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/interop-contrib
    See info in area-owners.md if you want to be subscribed.

  3. LideLinusZhang commented on Mar 9, 2026

    @LideLinusZhang
    Author

    Reproduction Solution: ComBugReproduction.zip

  4. m-celikba commented on Mar 9, 2026

    @m-celikba

    in the repro shared by @LideLinusZhang, if one of Interface3.cs or Interface4.cs is omitted, the projects build. If both are built an exception is thrown.

    @AaronRobinsonMSFT this is a variation of 111890. Can someone please take a look ?

  5. dotnet-policy-service commented on Apr 13, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/interop-contrib
    See info in area-owners.md if you want to be subscribed.

  6. added
    source-generator
    and removed
    untriaged
    on Jun 15, 2026
  7. added this to the 11.0.0 milestone on Jun 15, 2026
  8. dotnet-policy-service commented on Jun 15, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/interop-contrib
    See info in area-owners.md if you want to be subscribed.

  9. locked and limited conversation to collaborators on Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Runtime.InteropServicessource-generator

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions