Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

GeneratedComClass doesn't apply to inherited classes #94357

Closed

Description

@jtschuster

Placing GeneratedComClass on a base class doesn't enable deriving types to work with source generated COM.

Should we check for base classes that have the IComExposedDetails as well here?
https://github.com/dotnet/runtime/blob/df6fdefa27068126794b253d4d822706221a92db/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/Marshalling/IComExposedDetails.cs#L21C49-L21C49

	[GeneratedComInterface]
	[Guid("c5356681-8f8c-423a-959c-2d91f17215d3")]
	internal partial interface IFoo
	{
		int get();
	}

	[GeneratedComClass]
	[Guid("9f826481-4d92-4499-ab26-c40d9f77435b")]
	internal partial class FooBase : IFoo
	{
		public int get() => 42;
	}

	internal class Foo<T> :FooBase
	{
	}
int Main()
{
                        var cw = new StrategyBasedComWrappers();
			var foo = new Foo<int>();
			nint iptr = cw.GetOrCreateComInterfaceForObject(foo, CreateComInterfaceFlags.None);
			IFoo f = (IFoo)cw.GetOrCreateObjectForComInstance(iptr, CreateObjectFlags.None); // Fails - iptr does not implement IFoo
}

Activity

  1. ghost added
    untriaged
    on Nov 3, 2023
  2. AaronRobinsonMSFT commented on Nov 3, 2023

    @AaronRobinsonMSFT
    Member

    I'd like to understand this scenario before we go after it. I have some questions about how overrides are expected to and what benefits we gain as opposed to just having people place it on the most derived type.

  3. jtschuster commented on Nov 3, 2023

    @jtschuster
    MemberAuthor

    The more I think about it, I'm not sure there's a great way to do this without breaking trimming and AOT. Maybe we should just require it on all classes that are exposed to COM.

  4. jkoritzinsky commented on Nov 21, 2023

    @jkoritzinsky
    Member

    There's also no efficient way to detect this scenario in a source generator. We should just require it on all classes that are exposed to COM.

  5. AaronRobinsonMSFT commented on Nov 21, 2023

    @AaronRobinsonMSFT
    Member

    There's also no efficient way to detect this scenario in a source generator. We should just require it on all classes that are exposed to COM.

    Nice. Does it make sense to detect that if the immediate base class has GeneratedComClass that we emit a warning? I can imagine people doing odd things with managed inheritance for COM class implementation but I'm not sure that is something we should encourage.

  6. jkoritzinsky commented on Nov 21, 2023

    @jkoritzinsky
    Member

    Yes, we can write an analyzer that detects that case and emits a warning in an efficient way.

  7. added this to the 9.0.0 milestone on Jan 2, 2024
  8. ghost removed
    untriaged
    on Jan 2, 2024
  9. added
    in-pr
    on Jul 22, 2024
  10. locked and limited conversation to collaborators on Aug 23, 2024
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.InteropServicesin-pr

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions