Skip to content

Warning for partial ComImport types with members in more than one type part #59013

Description

@jnm2

The same reasoning applies as the reasoning for why partial enums wouldn't make sense. The meaning of a member in a ComImport type changes based on its order within the type.

There is currently no warning for a pair of source files like this, but there should be:

[ComImport]
partial interface ISomeInterface { void Foo(); }
partial interface ISomeInterface { void Bar(); }

There should be no warning for a case like this:

[ComImport]
partial interface ISomeInterface { void Foo(); }
[SomeInterface]
partial interface ISomeInterface
{
    public struct DoesNotAffectVTable { }
}

Why not warn for partial ComImport interfaces in the first place?

The source generator https://github.com/microsoft/CsWin32 is a new official vehicle for consuming Windows platform APIs. It generates most types as partial so that you can add customizations, but it doesn't do this for ComImport interfaces. @AArnott cited the danger described at the top. The use case for a partial ComImport interface was to add attributes:

namespace Windows.Win32.UI.Shell
{
    [CoClass(typeof(ShellLink))]
    internal partial interface IShellLinkW { }
}

This is safe, but adding a member would not be safe. Therefore the warning should only apply if more than one type part has members.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-Interop-coreclrcode-analyzerMarks an issue that suggests a Roslyn analyzer

    Type

    No type

    Projects

    Status
    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions