-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GeneratedComInterfaceAttribute can cause CS0108 error with two derived COM interfaces declaring methods with same name and signature #101240
Comments
@smourier My gut reaction here is, this is by design. If the interface is inheriting from a base interface what is the purpose of redeclaring a function with the same name? What is the relevant COM scenario that is being attempted here? Note that the new COM source generator is specifically designed to follow and enforce COM rules. |
The first reason is this is valid in COM. Nothing prevents you from doing this. Now, here is a real use case, consider this COM interface It derives (along the line) from
IDWriteTextLayout3 defines another GetLineMetrics like this:
The two first parameters are not of the same type in native world ( More generally you don't always have a way to discriminate between two methods with same name in .NET like you can do with the native definition, it's not always a 1-1 mapping. |
I didn't realize that the same name was valid across inheritance. I think the issue I'm thinking of is function overloading on the same interface. As a general note, the DirectDraw interfaces and just about everything in the graphics domain are not technically COM compliant. This is easy to see with the number of times they violate the core requirement of returning an Regardless of the above, the /cc @jkoritzinsky and @jtschuster |
A quick note on this statement. This assumption has no relation to the new COM source generator. We have intentionally broke with the built-in system because of the complexity and issues it created. This new approach definitely takes influence from the built-in system and endevours to provide similar utility, but it will deviate when the decision introduces confusion or oddities. |
Well, I won't fight that battle myself, but the necessity of Does that mean PS: I must admin the DWrite guys are the real rebels: no idl and funky .h headers :-) and ITextServices is the weirdest one: it's was not even defined with stdcall methods... |
Yes, we do and that is the long term plan. What we are currently discussing here is how to support the weird constructs. A simple workaround, as you noted, would be to rename the method to That being said, I think @jkoritzinsky and @jtschuster are clever enough to come up with some affordance to make this possible. For example, since the signatures are different in this case, I could see an argument being made that we enforce that in C# as well. Doesn't address all issues but since there is another workaround with renaming that seems reasonable to me. I'm going to look to them for how we address this though.
Exactly. Many of these interfaces are not COM compliant, which created subtle and incredibly bad design decisions in the built-in COM interop system. We are not going to be repeating these decisions, but will ensure there are reasonable and hopefully intuitive workarounds. |
Description
When using .NET8's GeneratedComInterfaceAttribute, we cannot define a derived interface with a method that has the same name and signature (parameters) as a method (unrelated in vtable) on a base interface, it raises CS0108 "'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended."
Reproduction Steps
Consider this simple .NET 8 project:
Add these interfaces definitions:
Expected behavior
I think it should just compile fine.
Actual behavior
Building creates these errors (all related):
Regression?
I don't think so since GeneratedComInterfaceAttribute is pretty new.
Known Workarounds
We can just rename IFace2's Blah with something else that doesn't conflict as COM names are not technically important but this raises lots of other issues, especially with .NET where names are.
Note that if if define IFace2's like this:
There are other errors, but the most interesting is this:
1>c:\temp\ConsoleApp6.Program.IFace2.cs(31,49,31,53): error CS0106: The modifier 'new' is not valid for this item
which is kinda strange, this typically works with .NET default marshaling.
Configuration
.NET 8.0.4 (tested on x64 but I don't think it's relevant here).
Other information
No response
The text was updated successfully, but these errors were encountered: