Skip to content

LibraryImport cannot handle a property named "System" #90299

@mstefarov

Description

@mstefarov

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

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions