Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/navigate/advanced-programming/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ items:
href: ../../standard/native-interop/preserve-sig.md
- name: Exceptions
href: ../../standard/native-interop/exceptions-interoperability.md
- name: Target ABI support
href: ../../standard/native-interop/abi-support.md
- name: Supplemental API remarks
items:
- name: The ComException class
Expand Down
36 changes: 36 additions & 0 deletions docs/standard/native-interop/abi-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Native interoperability ABI support - .NET
description: Defines the current support for interoperability with various ABIs.
ms.date: 10/25/2024
---
# Native interoperability ABI support

[Application Binary Interface](https://wikipedia.org/wiki/Application_binary_interface) (ABI) is the interface which run times and operating systems express low-level binary details. This can include calling conventions (that is, how parameters are passed and results returned), exception handling, as well as symbol mangling. The below list contains the names of languages, run times and even general technologies since these names tend to represent what users will be working with when looking for guidance on interoperability.

## Support table

| | Support | APIs |
|---|---------|------|
| **C** | ✔️ | <xref:System.Runtime.InteropServices.LibraryImportAttribute> provides source generated support in .NET 7+. Use <xref:System.Runtime.InteropServices.DllImportAttribute> when targeting earlier .NET versions. Refer to [Interop best practices](./best-practices.md) for additional guidance. |
| **C++** || [Guidance](#cpp) |
| **COM and `IUnknown`** | ✔️ | In .NET 5+, low-level, cross-platform, `IUnknown` lifetime support is provided by <xref:System.Runtime.InteropServices.ComWrappers>. In .NET 8+, <xref:System.Runtime.InteropServices.Marshalling.GeneratedComInterfaceAttribute> and <xref:System.Runtime.InteropServices.Marshalling.GeneratedComClassAttribute> provide source generated C# projections. The built-in COM interop system is limited to the Windows platforms and required on versions prior to .NET 5. |
| **Swift** | ✔️ | For .NET 9+, <xref:System.Runtime.InteropServices.Swift> namespace. |
| **Objective-C** | ✔️ | For .NET 8+, <xref:System.Runtime.InteropServices.ObjectiveC> namespace. |
| **golang** || [Guidance](#golang) |
| **ARM64EC** || [Note](#arm64ec) |

### <a name="cpp"></a> C++

The [C++ language](https://isocpp.org/) has no defined ABI across all .NET supported platforms and C++ compiler implementations (that is, MSVC, clang, and GCC). This lack of a stable ABI makes support difficult to provide.

The recommended way to interoperate with C++ is to export functions marked with `extern "C"` and call them as C functions.

### <a name="golang"></a> golang

The Go programming language is not supported for in-process interoperability. The Go runtime [imposes requirements](https://pkg.go.dev/os/signal#hdr-Non_Go_programs_that_call_Go_code) on being hosted in a process with another run time. Specifically, the use of the `SA_ONSTACK` flag on threads that run signal handlers. These requirements are not currently met by .NET and meeting them would impose non-trivial costs.

The recommended way to interoperate with golang is using a golang hosted process and communicate through an inter-process communication mechanism.

### <a name="arm64ec"></a> ARM64EC

The [ARM64EC](/cpp/build/arm64ec-windows-abi-conventions) ABI is not supported.
Loading