From 030a5288bc0c4598cd5e98d3e7e217b454072033 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 3 Feb 2025 19:46:01 -0800 Subject: [PATCH] Add note about internal representation of .NET runtime types --- docs/standard/native-interop/best-practices.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/standard/native-interop/best-practices.md b/docs/standard/native-interop/best-practices.md index ca439797deb37..8ed52a0994061 100644 --- a/docs/standard/native-interop/best-practices.md +++ b/docs/standard/native-interop/best-practices.md @@ -400,6 +400,8 @@ Pointers to structs in definitions must either be passed by `ref` or use `unsafe ✔️ DO use the C# `sizeof()` instead of `Marshal.SizeOf()` for blittable structures to improve performance. +❌ DON'T depend on internal representation of struct types exposed by .NET runtime libraries unless it is explicitly documented. + ❌ AVOID using classes to express complex native types through inheritance. ❌ AVOID using `System.Delegate` or `System.MulticastDelegate` fields to represent function pointer fields in structures.