microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
2.06k stars 87 forks source link

'PInvoke' is inaccessible due to its protection level #936

Closed ramjke closed 1 year ago

ramjke commented 1 year ago

Actual behavior

Screenshot 2023-05-20 at 17 43 15

The build is successful, but Visual Studio 17 shows an error: 'PInvoke' is inaccessible due to its protection level.

Expected behavior

There should be no error.

Repro steps

  1. NativeMethods.txt content:

    RegisterHotKey
    UnregisterHotKey
    GetSystemMetrics
    DwmSetWindowAttribute
    GetWindowLong
    GetWindowLongPtr
    GetWindowRect
    SetLastError
    SetWindowLongPtr
    SetWindowLong
    GetWindowRect
    SetWindowPos
    CallWindowProc
    GetDpiForWindow
    GetKeyboardLayout
    GetWindowThreadProcessId
    GetForegroundWindow
    CreateEvent
    SetEvent
    CoWaitForMultipleObjects
    SetForegroundWindow
  2. NativeMethods.json content (if present):

    {
    "$schema": "https://aka.ms/CsWin32.schema.json",
    "public": true
    }
  3. Any of your own code that should be shared?

Context

AArnott commented 1 year ago

Can you please attach a full repro? Your repro instructions don't include mention of two projects, but I can't imagine this failure without two projects being involved. In addition, the steps you do include look correct (e.g. you set public: true) in the json file, so the APIs should be public, making me wonder if the error you see is coming from a different project that doesn't set that value. So a full repro is necessary to investigate this.

AArnott commented 1 year ago

Closing due to no response.

Gavin-Williams commented 6 months ago

I'm seeing it with one project.

AArnott commented 6 months ago

@gavin-williams if you can share a repro, I'm willing to take a look. But if you see my earlier reply, I'm pretty sure it'll fall into that case which can be solved.