dotnet-native-interop

Guide .NET P/Invoke calls to native libraries with marshalling and cross-platform resolution.

1|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/rudironsoni/dotnet-agent-harness --skill dotnet-native-interop-rudironsoni
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-native-interop
Source: https://github.com/rudironsoni/dotnet-agent-harness/tree/main/.rulesync/skills/dotnet-native-interop
Command: npx skills add https://github.com/rudironsoni/dotnet-agent-harness --skill dotnet-native-interop-rudironsoni

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill simplifies the process of calling native C/C++ libraries from .NET applications, enabling seamless integration with existing native codebases.

Core Features & Use Cases

  • P/Invoke Declarations: Supports both modern [LibraryImport] (.NET 7+) and legacy [DllImport] attributes.
  • Cross-Platform Resolution: Provides strategies for handling platform-specific library names and loading.
  • Marshalling: Demonstrates patterns for marshalling structs, strings, and other data types between .NET and native code.
  • Use Case: Integrate a high-performance native image processing library into your .NET application to leverage its speed and functionality.

Quick Start

Use the dotnet-native-interop skill to demonstrate calling a native function using [LibraryImport].

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?

To call a native C++ library from .NET, you use P/Invoke with the [LibraryImport] or [DllImport] attributes to declare native functions. This Skill provides guidance on generating these declarations and handling platform-specific library loading.

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

[LibraryImport] is the modern P/Invoke attribute introduced in .NET 7+, offering source-generated marshalling, while [DllImport] is the legacy runtime-based approach. This Skill demonstrates patterns for using both attributes to integrate native code.

How do I marshal strings and structs between .NET and native code?

Marshalling strings and structs between .NET and native code requires defining compatible data types and using attributes to control memory layout. This Skill demonstrates patterns for correctly passing structs, strings, and other data types across the boundary.

How do I resolve native library names across Windows, macOS, and Linux in .NET?

Resolving native library names across Windows, macOS, and Linux requires using NativeLibrary.SetDllImportResolver to handle platform-specific loading. This Skill provides strategies for cross-platform library resolution and loading.

How do I safely handle native resources in .NET interop?

Safely handling native resources in .NET interop involves using SafeHandle to wrap native pointers and ensure proper cleanup. This Skill addresses safe handling of native resources to prevent memory leaks during P/Invoke calls.