
Description
dotnet-pinvoke is an agent skill for calling native C and C++ libraries from .NET using P/Invoke. It covers both DllImport, which dates from .NET Framework 1.0, and LibraryImport, a source-generated form available from .NET 7. The skill focuses on the common failure points: function signatures that do not match the native header, string marshalling, memory ownership and lifetime, and calling conventions. It helps when writing a new declaration from a C header, reviewing existing signatures, wrapping a whole C library, or diagnosing an AccessViolationException, a DllNotFoundException or silent data corruption at the native boundary. It also covers moving DllImport declarations to LibraryImport for trimming and Native AOT. For .NET Framework code it recommends DllImport, and where Native AOT is required it recommends LibraryImport.…
Highlights
- Writes DllImport and LibraryImport declarations from C headers
- Reviews signatures for type sizes, calling conventions and string encoding
- Guides memory lifetime for native buffers and handles
- Helps migrate DllImport to LibraryImport for AOT
Ratings & Reviews
No ratings yet
Be the first to rate dotnet-pinvoke.
People also visit
dotnet-pinvoke FAQ
What does this skill help with?
Native interop in .NET: writing and reviewing P/Invoke signatures, marshalling strings, managing native memory, wrapping C libraries, and debugging crashes at the native boundary.
DllImport or LibraryImport?
Use DllImport when targeting .NET Framework. For .NET 7 and later, LibraryImport is preferred for new code, and it is the only option when Native AOT is required.
Which errors does it help diagnose?
AccessViolationException, DllNotFoundException, silent data corruption, and memory leaks or heap corruption involving native handles or buffers.
How do I install it?
Run npx skills add https://github.com/dotnet/skills --skill dotnet-pinvoke in your project.
What security audits has it passed?
Gen Agent Trust Hub: Pass. Socket: Pass. Snyk: Pass.
What are the best dotnet-pinvoke alternatives?
Popular alternatives to dotnet-pinvoke include dart-setup-ffi-assets, dotnet-skills and dart-use-ffigen. See all dotnet-pinvoke alternatives











