Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Declares and reviews .NET P/Invoke and LibraryImport bindings to C/C++ libraries, covering marshalling, memory lifetime, and SafeHandle.
64% 95%+32 ptsof test cases passed
Passed 21 of 22 test cases with the skill, and 14 of 22 without it.
I am writing a `LibraryImport` declaration in .NET 8 for the Windows API function `GetModuleFileNameW`. What string marshalling options should be configured on the attribute?
The method declaration sets SetLastPInvokeError to true
This test ran on v1. v2 is the current version and hasn’t been tested on gemini-3.6-flash yet.
3 of 3 safety checks passed
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.
[DllImport] or [LibraryImport] declaration from a C/C++ headerAccessViolationException, DllNotFoundException, or silent data corruption at the native boundaryDllImport declarations to LibraryImport for AOT/trimming compatibilityDllImport to LibraryImport unless the user asks or AOT/trimming is an explicit requirement.| Input | Required | Description |
|---|---|---|
| Native header or documentation | Yes | C/C++ function signatures, struct definitions, calling conventions |
| Target framework | Yes | Determines whether to use DllImport or LibraryImport |
| Target platforms | Recommended | Affects type sizes (long, size_t) and library naming |
| Memory ownership contract | Yes | Who allocates and who frees each buffer or handle |
Agent behavior: When documentation and native headers diverge, always trust the header. Online documentation (including official Win32 API docs) frequently omits or simplifies details about types, calling conventions, and struct layout that are critical for correct P/Invoke signatures.
Next to this one in the catalogue, plus more from the same author.