.NET P/Invoke Calling native code from .NET is powerful but unforgiving. Incorrect signatures, garbled strings, and leaked or freed memory are the most common sources of bugs — all can manifest as intermittent crashes, silent data corruption, or access violations far from the actual defect. This skill covers both DllImport (available since .NET Framework 1.0) and LibraryImport (source-generated, .NET 7+). When targeting .NET Framework, always use DllImport . When targeting .NET 7+, prefer LibraryImport for new code. When native AOT is a requirement, LibraryImport is the only option. When to Use This Skill Writing a new [DllImport] or [LibraryImport] declaration from a C/C++ header Reviewing P/Invoke signatures for correctness (type sizes, calling conventions, string encoding) Wrapping an entire C library for use from .NET Debugging AccessViolationException , DllNotFoundException , or silent data corruption at the native boundary Migrating DllImport declarations to LibraryImport for AOT/trimming compatibility Diagnosing memory leaks or heap corruption involving native handles or buffers Stop Signals Show more Installs 895 Repository dotnet/skills GitHub Stars 5.0K First Seen Mar 10, 2026 Security Audits Gen Agent Trust Hub Pass Socket Fail Snyk Pass
dotnet-pinvoke
安装
npx skills add https://github.com/dotnet/skills --skill dotnet-pinvoke