dotnet-native-interop

Call native libraries from .NET using P/Invoke patterns.

10|Updated Jan 28, 2026
One-click install
npx skills add https://github.com/AGIBuild/Agibuild.Fulora --skill dotnet-native-interop
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-native-interop
Source: https://github.com/AGIBuild/Agibuild.Fulora/tree/main/.cursor/skills/dotnet-native-interop
Command: npx skills add https://github.com/AGIBuild/Agibuild.Fulora --skill dotnet-native-interop

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance on how to safely and efficiently call native libraries (like C/C++ DLLs or SOs) from your .NET applications using Platform Invoke (P/Invoke).

Core Features & Use Cases

  • Modern P/Invoke: Demonstrates the use of [LibraryImport] (.NET 7+) for AOT-compatible, source-generated marshalling.
  • Legacy P/Invoke: Covers [DllImport] for older .NET versions and specific scenarios.
  • Cross-Platform Resolution: Explains how to handle different library names and loading mechanisms across Windows, macOS, Linux, iOS, and Android.
  • Marshalling: Details how to correctly marshal various data types, including structs, strings, and function pointers.
  • Resource Management: Emphasizes using SafeHandle for robust native resource lifetime management.
  • Use Case: Integrate a high-performance native image processing library into your .NET desktop application, ensuring correct data transfer and resource cleanup across different operating systems.

Quick Start

Use the dotnet-native-interop skill to learn how to call a C function named 'process_data' from a native library 'mylib.dll' on Windows.

Frequently Asked Questions about dotnet-native-interop

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I call a native C library from .NET using P/Invoke?

You call native C libraries from .NET using P/Invoke by applying the `[LibraryImport]` or `[DllImport]` attribute to external method declarations, enabling the managed runtime to invoke unmanaged functions.

What is the difference between LibraryImport and DllImport in .NET?

`[LibraryImport]` is the modern .NET 7+ attribute generating AOT-compatible source-generated marshalling, whereas `[DllImport]` is the legacy P/Invoke mechanism relying on runtime marshalling for older .NET versions.

How do I marshal strings and structs when calling native code in .NET?

To marshal strings and structs in .NET native interop, you configure the P/Invoke signature with specific attributes to ensure correct data transfer and memory layout between managed and unmanaged memory.

Does .NET P/Invoke work across Windows, macOS, Linux, iOS, and Android?

Yes, .NET P/Invoke works across Windows, macOS, Linux, iOS, and Android by handling different native library names and loading mechanisms during cross-platform library resolution.

How do I manage native resource lifetimes safely in .NET interop?

You manage native resource lifetimes safely in .NET interop by using `SafeHandle` wrappers, which guarantee robust resource cleanup and prevent memory leaks when calling unmanaged libraries.

Why does my .NET P/Invoke call fail with an AOT compilation error?

P/Invoke calls fail with AOT compilation errors when using legacy `[DllImport]` due to runtime marshalling dependencies; switching to the source-generated `[LibraryImport]` attribute ensures AOT compatibility.