Skip to content
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

[ComInterfaceGenerator] Custom enum return type in base interface unrecognized when processing derived interface #87915

Closed
lordmilko opened this issue Jun 22, 2023 · 3 comments

Comments

@lordmilko
Copy link

Description

The ComInterfaceGenerator throws an error when attempting to parse a derived interface whose base interface contains an unqualified custom enum type as the return type of a method.

For example, attempting to compile the following code

public enum HRESULT
{
}

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("4BBA36C0-20BB-4DFF-9241-71992D498B39")]
[GeneratedComInterface]
public partial interface Base
{
    // Base will generate its wrapper successfully, but Derived will complain Base.M1's HRESULT type is unknown
    HRESULT M1();
}

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("8BCFEC21-589D-45BC-908C-E038252F3453")]
[GeneratedComInterface]
public partial interface Derived : Base
{
    HRESULT M2();
}

generates the following errors

error CS0246: The type or namespace name 'HRESULT' could not be found (are you missing a using directive or an assembly reference?)
error CS0539: 'InterfaceImplementation.M1()' in explicit interface declaration is not found among members of the interface that can be implemented
  • If Derived is modified to not derive from Base the application successfully compiles
  • Changing the return type of M1 to a runtime type like int successfully compiles
  • Fully qualifying the return type of M1 (e.g. ConsoleApp1.HRESULT M1()) also successfully compiles
  • Specifying an argument of type HRESULT to M1 with return type void successfully compiles - the issue only occurs when our custom type is used as a return type

This behavior occurs regardless of whether PreserveSigAttribute is specified

Reproduction Steps

public enum HRESULT
{
}

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("4BBA36C0-20BB-4DFF-9241-71992D498B39")]
[GeneratedComInterface]
public partial interface Base
{
    HRESULT M1();
}

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("8BCFEC21-589D-45BC-908C-E038252F3453")]
[GeneratedComInterface]
public partial interface Derived : Base
{
    HRESULT M2();
}

Expected behavior

Custom return types are properly recognized without needing to fully qualify their namespaces

Actual behavior

error CS0246: The type or namespace name 'HRESULT' could not be found (are you missing a using directive or an assembly reference?)
error CS0539: 'InterfaceImplementation.M1()' in explicit interface declaration is not found among members of the interface that can be implemented

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 22, 2023
@ghost
Copy link

ghost commented Jun 22, 2023

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

Issue Details

Description

The ComInterfaceGenerator throws an error when attempting to parse a derived interface whose base interface contains an unqualified custom enum type as the return type of a method.

For example, attempting to compile the following code

public enum HRESULT
{
}

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("4BBA36C0-20BB-4DFF-9241-71992D498B39")]
[GeneratedComInterface]
public partial interface Base
{
    // Base will generate its wrapper successfully, but Derived will complain Base.M1's HRESULT type is unknown
    HRESULT M1();
}

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("8BCFEC21-589D-45BC-908C-E038252F3453")]
[GeneratedComInterface]
public partial interface Derived : Base
{
    HRESULT M2();
}

generates the following errors

error CS0246: The type or namespace name 'HRESULT' could not be found (are you missing a using directive or an assembly reference?)
error CS0539: 'InterfaceImplementation.M1()' in explicit interface declaration is not found among members of the interface that can be implemented
  • If Derived is modified to not derive from Base the application successfully compiles
  • Changing the return type of M1 to a runtime type like int successfully compiles
  • Fully qualifying the return type of M1 (e.g. ConsoleApp1.HRESULT M1()) also successfully compiles
  • Specifying an argument of type HRESULT to M1 with return type void successfully compiles - the issue only occurs when our custom type is used as a return type

This behavior occurs regardless of whether PreserveSigAttribute is specified

Reproduction Steps

public enum HRESULT
{
}

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("4BBA36C0-20BB-4DFF-9241-71992D498B39")]
[GeneratedComInterface]
public partial interface Base
{
    HRESULT M1();
}

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("8BCFEC21-589D-45BC-908C-E038252F3453")]
[GeneratedComInterface]
public partial interface Derived : Base
{
    HRESULT M2();
}

Expected behavior

Custom return types are properly recognized without needing to fully qualify their namespaces

Actual behavior

error CS0246: The type or namespace name 'HRESULT' could not be found (are you missing a using directive or an assembly reference?)
error CS0539: 'InterfaceImplementation.M1()' in explicit interface declaration is not found among members of the interface that can be implemented

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: lordmilko
Assignees: -
Labels:

area-System.Runtime.InteropServices, untriaged

Milestone: -

@jkoritzinsky
Copy link
Member

I believe this has been fixed by #87661

@jkoritzinsky jkoritzinsky removed the untriaged New issue has not been triaged by the area owner label Jun 22, 2023
@jkoritzinsky jkoritzinsky added this to the 8.0.0 milestone Jun 22, 2023
@AaronRobinsonMSFT
Copy link
Member

@lordmilko We'll close this for now as I agree with @jkoritzinsky. Please let us know if this wasn't addressed in the next preview.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants