Skip to content

Error CS0122: '{0}' is inaccessible due to its protection level #1671

@rezanid

Description

@rezanid

Actual behavior

Build error for any type generated by CsWin32, if a referenced assembly also contains the type as internal! Example error:

  • error CS0122: 'HRESULT' is inaccessible due to its protection level.

Expected behavior

When using any type from CsWin32 that is generated into the local assembly - even if the type also exist in a referenced assembly - I am expecting the generated type to be used.

Repro steps

  1. NativeMethods.txt content:
use pointers.
COLORREF
IsZoomed
DefWindowProc
SetWindowPos
GetWindowRect
PostMessage
DwmSetWindowAttribute
SHAppBarMessage
S_OK
E_INVALIDARG
HRESULT_FROM_WIN32
MAKELONG
LOWORD
HIWORD

  1. NativeMethods.json content (if present): Not present

  2. Any of your own code that should be shared?

Context

  • CsWin32 version: 0.3.269+368685089b.RR
  • Win32Metadata version (if explicitly set by project):
  • Target Framework: net48
  • LangVersion (if explicitly set by project): 13.0
  • OS: Win11 ARM

The repo can be found below:

Note

I suggest downloading this single project (not the entire solution) to easily build:

https://github.com/rezanid/xrmtools/blob/vsix-hybrid/src/XrmTools.Shell/XrmTools.Shell.csproj

Additional Context

I also tried building outside Visual Studio using dotnet build. This command successfully builds the project. Then I added the following piece to the project and tested again. This time also dotnet build fails similarly.

  <PropertyGroup>
    <CsWin32RunAsBuildTask>true</CsWin32RunAsBuildTask>
  </PropertyGroup>

I guess the source generator has logic to detect if the type already exists, but it does not distinguish between type exist in the current assembly or a referenced one or this logic doesn't work when directly building with MSBuild and only via dotnet build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions