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

LibraryImport cannot handle a property named "System" #90299

Closed
mstefarov opened this issue Aug 10, 2023 · 5 comments · Fixed by #90339
Closed

LibraryImport cannot handle a property named "System" #90299

mstefarov opened this issue Aug 10, 2023 · 5 comments · Fixed by #90339
Assignees
Labels
area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature
Milestone

Comments

@mstefarov
Copy link

Description

If there is a property named "System" in scope where LibraryImport is used, the generated code will fail to build with error CS0120.

This is probably caused by ambiguity between "System" namespace and "System" property. Perhaps generated code should prefix types with global::?

Reproduction Steps

using System;
using System.Runtime.InteropServices;

namespace ClassLibrary1;

public partial class Class1
{
    public int System => GetSystem(out _);

    [LibraryImport("foo.dll")]
    private static partial int GetSystem(out IntPtr handle);
}

Expected behavior

Generated code builds successfully.

Actual behavior

Build fails with an error in generated code:

LibraryImports.g.cs(10,13,10,19): error CS0120: An object reference is required for the non-static field, method, or property 'Class1.System'

Regression?

No response

Known Workarounds

No response

Configuration

net7.0 on Windows 10 x64, using VS 17.7.0

Other information

No response

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

ghost commented Aug 10, 2023

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

Issue Details

Description

If there is a property named "System" in scope where LibraryImport is used, the generated code will fail to build with error CS0120.

This is probably caused by ambiguity between "System" namespace and "System" property. Perhaps generated code should prefix types with global::?

Reproduction Steps

using System;
using System.Runtime.InteropServices;

namespace ClassLibrary1;

public partial class Class1
{
    public int System => GetSystem(out _);

    [LibraryImport("foo.dll")]
    private static partial int GetSystem(out IntPtr handle);
}

Expected behavior

Generated code builds successfully.

Actual behavior

Build fails with an error in generated code:

LibraryImports.g.cs(10,13,10,19): error CS0120: An object reference is required for the non-static field, method, or property 'Class1.System'

Regression?

No response

Known Workarounds

No response

Configuration

net7.0 on Windows 10 x64, using VS 17.7.0

Other information

No response

Author: mstefarov
Assignees: -
Labels:

area-System.Runtime.InteropServices

Milestone: -

@huoyaoyuan huoyaoyuan added the source-generator Indicates an issue with a source generator feature label Aug 10, 2023
@AaronRobinsonMSFT AaronRobinsonMSFT removed the untriaged New issue has not been triaged by the area owner label Aug 10, 2023
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 8.0.0 milestone Aug 10, 2023
@AaronRobinsonMSFT
Copy link
Member

@jkoritzinsky Are we missing a global:: prefix in some case?

@jtschuster
Copy link
Member

Looks like in SkipInit and the DllImportAttribute application we're missing it.

@jtschuster jtschuster self-assigned this Aug 10, 2023
@AaronRobinsonMSFT
Copy link
Member

I assume this is an easy fix.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Aug 10, 2023
@dotMorten
Copy link

I assume this is an easy fix.

I just looked at the PR 😬 #Jinx

@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Aug 11, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature
Projects
None yet
5 participants