You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GeneratedComClass doesn't apply to inherited classes #94357
[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
}
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.
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.
Reacted by Aaron R Robinson and Jeremy Koritzinsky
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.
Activity
AaronRobinsonMSFT commentedon Nov 3, 2023
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.
jtschuster commentedon Nov 3, 2023
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.
jkoritzinsky commentedon Nov 21, 2023
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.
AaronRobinsonMSFT commentedon Nov 21, 2023
Nice. Does it make sense to detect that if the immediate base class has
GeneratedComClassthat 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.jkoritzinsky commentedon Nov 21, 2023
Yes, we can write an analyzer that detects that case and emits a warning in an efficient way.