Skip to content

[API Proposal]: Mark System.Runtime.InteropServices APIs as caller-unsafe #129750

Closed

Description

@EgorBo

Background and motivation

#125145

API Proposal

namespace System.Runtime.InteropServices.Marshalling;

public partial class StrategyBasedComWrappers : System.Runtime.InteropServices.ComWrappers
{
+   /// <safety>Wraps a raw, caller-supplied COM (IUnknown) pointer that the override dereferences</safety>
+   unsafe
    protected sealed override object CreateObject(nint externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags);

+   /// <safety>Wraps a raw, caller-supplied COM (IUnknown) pointer that the override dereferences</safety>
+   unsafe
    protected sealed override object? CreateObject(nint externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags, object? userState, out System.Runtime.InteropServices.CreatedWrapperFlags wrapperFlags);
}
namespace System.IO;

public partial class UnmanagedMemoryAccessor : System.IDisposable
{
+   /// <safety>Reinterprets unmanaged memory as a T[]; T's padding and any pointer/reference fields are produced from raw bytes</safety>
+   unsafe
    public int ReadArray<T>(long position, T[] array, int offset, int count) where T : struct;

+   /// <safety>Reinterprets unmanaged memory as a T; T's padding and any pointer/reference fields are produced from raw bytes</safety>
+   unsafe
    public void Read<T>(long position, out T structure) where T : struct;

+   /// <safety>Writes T's raw bytes (including padding) into unmanaged memory</safety>
+   unsafe
    public void WriteArray<T>(long position, T[] array, int offset, int count) where T : struct;

+   /// <safety>Writes T's raw bytes (including padding) into unmanaged memory</safety>
+   unsafe
    public void Write<T>(long position, ref T structure) where T : struct;
}
namespace System.Runtime.InteropServices;

public static partial class Marshal
{
+   /// <safety>Dereferences a raw, caller-supplied IUnknown pointer</safety>
+   unsafe
    public static int AddRef(System.IntPtr pUnk);

+   /// <safety>Dereferences a raw, caller-supplied IUnknown pointer</safety>
+   unsafe
    public static System.IntPtr CreateAggregatedObject(System.IntPtr pOuter, object o);

+   /// <safety>Dereferences a raw, caller-supplied IUnknown pointer</safety>
+   unsafe
    public static System.IntPtr CreateAggregatedObject<T>(System.IntPtr pOuter, T o) where T : notnull;

+   /// <safety>Writes to a raw, caller-supplied destination address with no bounds check</safety>
+   unsafe
    public static void Copy(byte[] source, int startIndex, System.IntPtr destination, int length);

+   /// <safety>Writes to a raw, caller-supplied destination address with no bounds check</safety>
+   unsafe
    public static void Copy(char[] source, int startIndex, System.IntPtr destination, int length);

+   /// <safety>Writes to a raw, caller-supplied destination address with no bounds check</safety>
+   unsafe
    public static void Copy(double[] source, int startIndex, System.IntPtr destination, int length);

+   /// <safety>Writes to a raw, caller-supplied destination address with no bounds check</safety>
+   unsafe
    public static void Copy(short[] source, int startIndex, System.IntPtr destination, int length);

+   /// <safety>Writes to a raw, caller-supplied destination address with no bounds check</safety>
+   unsafe
    public static void Copy(int[] source, int startIndex, System.IntPtr destination, int length);

+   /// <safety>Writes to a raw, caller-supplied destination address with no bounds check</safety>
+   unsafe
    public static void Copy(long[] source, int startIndex, System.IntPtr destination, int length);

+   /// <safety>Reads from a raw, caller-supplied source address with no bounds check</safety>
+   unsafe
    public static void Copy(System.IntPtr source, byte[] destination, int startIndex, int length);

+   /// <safety>Reads from a raw, caller-supplied source address with no bounds check</safety>
+   unsafe
    public static void Copy(System.IntPtr source, char[] destination, int startIndex, int length);

+   /// <safety>Reads from a raw, caller-supplied source address with no bounds check</safety>
+   unsafe
    public static void Copy(System.IntPtr source, double[] destination, int startIndex, int length);

+   /// <safety>Reads from a raw, caller-supplied source address with no bounds check</safety>
+   unsafe
    public static void Copy(System.IntPtr source, short[] destination, int startIndex, int length);

+   /// <safety>Reads from a raw, caller-supplied source address with no bounds check</safety>
+   unsafe
    public static void Copy(System.IntPtr source, int[] destination, int startIndex, int length);

+   /// <safety>Reads from a raw, caller-supplied source address with no bounds check</safety>
+   unsafe
    public static void Copy(System.IntPtr source, long[] destination, int startIndex, int length);

+   /// <safety>Reads from a raw, caller-supplied source address with no bounds check</safety>
+   unsafe
    public static void Copy(System.IntPtr source, System.IntPtr[] destination, int startIndex, int length);

+   /// <safety>Reads from a raw, caller-supplied source address with no bounds check</safety>
+   unsafe
    public static void Copy(System.IntPtr source, float[] destination, int startIndex, int length);

+   /// <safety>Writes to a raw, caller-supplied destination address with no bounds check</safety>
+   unsafe
    public static void Copy(System.IntPtr[] source, int startIndex, System.IntPtr destination, int length);

+   /// <safety>Writes to a raw, caller-supplied destination address with no bounds check</safety>
+   unsafe
    public static void Copy(float[] source, int startIndex, System.IntPtr destination, int length);

+   /// <safety>Runs marshalling cleanup over a struct at a raw, caller-supplied address</safety>
+   unsafe
    public static void DestroyStructure(System.IntPtr ptr, System.Type structuretype);

+   /// <safety>Runs marshalling cleanup over a struct at a raw, caller-supplied address</safety>
+   unsafe
    public static void DestroyStructure<T>(System.IntPtr ptr);

+   /// <safety>Frees a raw, caller-supplied native pointer; an invalid pointer corrupts the allocator heap</safety>
+   unsafe
    public static void FreeBSTR(System.IntPtr ptr);

+   /// <safety>Frees a raw, caller-supplied native pointer; an invalid pointer corrupts the allocator heap</safety>
+   unsafe
    public static void FreeCoTaskMem(System.IntPtr ptr);

+   /// <safety>Frees a raw, caller-supplied native pointer; an invalid pointer corrupts the allocator heap</safety>
+   unsafe
    public static void FreeHGlobal(System.IntPtr hglobal);

+   /// <safety>Treats a raw, caller-supplied address as callable code (invoked through the returned delegate)</safety>
+   unsafe
    public static System.Delegate GetDelegateForFunctionPointer(System.IntPtr ptr, System.Type t);

+   /// <safety>Treats a raw, caller-supplied address as callable code (invoked through the returned delegate)</safety>
+   unsafe
    public static TDelegate GetDelegateForFunctionPointer<TDelegate>(System.IntPtr ptr);

+   /// <safety>Dereferences a raw, caller-supplied IErrorInfo pointer</safety>
+   unsafe
    public static System.Exception? GetExceptionForHR(int errorCode, System.IntPtr errorInfo);

+   /// <safety>Dereferences a raw COM IntPtr</safety>
+   unsafe
    public static System.Exception? GetExceptionForHR(int errorCode, in System.Guid iid, System.IntPtr pUnk);

+   /// <safety>Writes a VARIANT through a raw, caller-supplied address</safety>
+   unsafe
    public static void GetNativeVariantForObject(object? obj, System.IntPtr pDstNativeVariant);

+   /// <safety>Writes a VARIANT through a raw, caller-supplied address</safety>
+   unsafe
    public static void GetNativeVariantForObject<T>(T? obj, System.IntPtr pDstNativeVariant);

+   /// <safety>Dereferences a raw, caller-supplied IUnknown pointer</safety>
+   unsafe
    public static object GetObjectForIUnknown(System.IntPtr pUnk);

+   /// <safety>Reads a VARIANT from a raw, caller-supplied address</safety>
+   unsafe
    public static object? GetObjectForNativeVariant(System.IntPtr pSrcNativeVariant);

+   /// <safety>Reads a VARIANT from a raw, caller-supplied address</safety>
+   unsafe
    public static T? GetObjectForNativeVariant<T>(System.IntPtr pSrcNativeVariant);

+   /// <safety>Reads a VARIANT array from a raw, caller-supplied address</safety>
+   unsafe
    public static object?[] GetObjectsForNativeVariants(System.IntPtr aSrcNativeVariant, int cVars);

+   /// <safety>Reads a VARIANT array from a raw, caller-supplied address</safety>
+   unsafe
    public static T[] GetObjectsForNativeVariants<T>(System.IntPtr aSrcNativeVariant, int cVars);

+   /// <safety>Dereferences a raw, caller-supplied IUnknown pointer</safety>
+   unsafe
    public static object GetTypedObjectForIUnknown(System.IntPtr pUnk, System.Type t);

+   /// <safety>Dereferences a raw, caller-supplied IUnknown pointer</safety>
+   unsafe
    public static object GetUniqueObjectForIUnknown(System.IntPtr unknown);

+   /// <safety>Reads a string from a raw, caller-supplied address, scanning memory for its length/terminator</safety>
+   unsafe
    public static string? PtrToStringAnsi(System.IntPtr ptr);

+   /// <safety>Reads a string from a raw, caller-supplied address, scanning memory for its length/terminator</safety>
+   unsafe
    public static string PtrToStringAnsi(System.IntPtr ptr, int len);

+   /// <safety>Reads a string from a raw, caller-supplied address, scanning memory for its length/terminator</safety>
+   unsafe
    public static string? PtrToStringAuto(System.IntPtr ptr);

+   /// <safety>Reads a string from a raw, caller-supplied address, scanning memory for its length/terminator</safety>
+   unsafe
    public static string? PtrToStringAuto(System.IntPtr ptr, int len);

+   /// <safety>Reads a string from a raw, caller-supplied address, scanning memory for its length/terminator</safety>
+   unsafe
    public static string PtrToStringBSTR(System.IntPtr ptr);

+   /// <safety>Reads a string from a raw, caller-supplied address, scanning memory for its length/terminator</safety>
+   unsafe
    public static string? PtrToStringUni(System.IntPtr ptr);

+   /// <safety>Reads a string from a raw, caller-supplied address, scanning memory for its length/terminator</safety>
+   unsafe
    public static string PtrToStringUni(System.IntPtr ptr, int len);

+   /// <safety>Reads a string from a raw, caller-supplied address, scanning memory for its length/terminator</safety>
+   unsafe
    public static string? PtrToStringUTF8(System.IntPtr ptr);

+   /// <safety>Reads a string from a raw, caller-supplied address, scanning memory for its length/terminator</safety>
+   unsafe
    public static string PtrToStringUTF8(System.IntPtr ptr, int byteLen);

+   /// <safety>Reads a struct (including padding) from a raw, caller-supplied address</safety>
+   unsafe
    public static void PtrToStructure(System.IntPtr ptr, object structure);

+   /// <safety>Reads a struct (including padding) from a raw, caller-supplied address</safety>
+   unsafe
    public static object? PtrToStructure(System.IntPtr ptr, System.Type structureType);

+   /// <safety>Reads a struct (including padding) from a raw, caller-supplied address</safety>
+   unsafe
    public static T? PtrToStructure<T>(System.IntPtr ptr);

+   /// <safety>Reads a struct (including padding) from a raw, caller-supplied address</safety>
+   unsafe
    public static void PtrToStructure<T>(System.IntPtr ptr, T structure);

+   /// <safety>Dereferences a raw, caller-supplied IUnknown pointer</safety>
+   unsafe
    public static int QueryInterface(System.IntPtr pUnk, in System.Guid iid, out System.IntPtr ppv);

+   /// <safety>Reads through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static byte ReadByte(System.IntPtr ptr);

+   /// <safety>Reads through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static byte ReadByte(System.IntPtr ptr, int ofs);

+   /// <safety>Reads at an unchecked offset inside a pinned object; the offset is not bounds-checked and may fall outside the object</safety>
+   unsafe
    public static byte ReadByte(object ptr, int ofs);

+   /// <safety>Reads through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static short ReadInt16(System.IntPtr ptr);

+   /// <safety>Reads through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static short ReadInt16(System.IntPtr ptr, int ofs);

+   /// <safety>Reads at an unchecked offset inside a pinned object; the offset is not bounds-checked and may fall outside the object</safety>
+   unsafe
    public static short ReadInt16(object ptr, int ofs);

+   /// <safety>Reads through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static int ReadInt32(System.IntPtr ptr);

+   /// <safety>Reads through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static int ReadInt32(System.IntPtr ptr, int ofs);

+   /// <safety>Reads at an unchecked offset inside a pinned object; the offset is not bounds-checked and may fall outside the object</safety>
+   unsafe
    public static int ReadInt32(object ptr, int ofs);

+   /// <safety>Reads through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static long ReadInt64(System.IntPtr ptr);

+   /// <safety>Reads through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static long ReadInt64(System.IntPtr ptr, int ofs);

+   /// <safety>Reads at an unchecked offset inside a pinned object; the offset is not bounds-checked and may fall outside the object</safety>
+   unsafe
    public static long ReadInt64(object ptr, int ofs);

+   /// <safety>Reads through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static System.IntPtr ReadIntPtr(System.IntPtr ptr);

+   /// <safety>Reads through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static System.IntPtr ReadIntPtr(System.IntPtr ptr, int ofs);

+   /// <safety>Reads at an unchecked offset inside a pinned object; the offset is not bounds-checked and may fall outside the object</safety>
+   unsafe
    public static System.IntPtr ReadIntPtr(object ptr, int ofs);

+   /// <safety>Reallocates a raw, caller-supplied native pointer; an invalid pointer corrupts the allocator heap</safety>
+   unsafe
    public static System.IntPtr ReAllocCoTaskMem(System.IntPtr pv, int cb);

+   /// <safety>Reallocates a raw, caller-supplied native pointer; an invalid pointer corrupts the allocator heap</safety>
+   unsafe
    public static System.IntPtr ReAllocHGlobal(System.IntPtr pv, System.IntPtr cb);

+   /// <safety>Dereferences a raw, caller-supplied IUnknown pointer</safety>
+   unsafe
    public static int Release(System.IntPtr pUnk);

+   /// <safety>Writes a struct's bytes (including padding) to a raw, caller-supplied address</safety>
+   unsafe
    public static void StructureToPtr(object structure, System.IntPtr ptr, bool fDeleteOld);

+   /// <safety>Writes a struct's bytes (including padding) to a raw, caller-supplied address</safety>
+   unsafe
    public static void StructureToPtr<T>(T structure, System.IntPtr ptr, bool fDeleteOld);

+   /// <safety>Dereferences a raw, caller-supplied IErrorInfo pointer</safety>
+   unsafe
    public static void ThrowExceptionForHR(int errorCode, System.IntPtr errorInfo);

+   /// <safety>Dereferences a raw COM IntPtr</safety>
+   unsafe
    public static void ThrowExceptionForHR(int errorCode, in System.Guid iid, System.IntPtr pUnk);

+   /// <safety>Writes through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static void WriteByte(System.IntPtr ptr, byte val);

+   /// <safety>Writes through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static void WriteByte(System.IntPtr ptr, int ofs, byte val);

+   /// <safety>Writes at an unchecked offset inside a pinned object; the offset is not bounds-checked and may fall outside the object</safety>
+   unsafe
    public static void WriteByte(object ptr, int ofs, byte val);

+   /// <safety>Writes through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static void WriteInt16(System.IntPtr ptr, char val);

+   /// <safety>Writes through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static void WriteInt16(System.IntPtr ptr, short val);

+   /// <safety>Writes through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static void WriteInt16(System.IntPtr ptr, int ofs, char val);

+   /// <safety>Writes through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static void WriteInt16(System.IntPtr ptr, int ofs, short val);

+   /// <safety>Writes at an unchecked offset inside a pinned object; the offset is not bounds-checked and may fall outside the object</safety>
+   unsafe
    public static void WriteInt16(object ptr, int ofs, char val);

+   /// <safety>Writes at an unchecked offset inside a pinned object; the offset is not bounds-checked and may fall outside the object</safety>
+   unsafe
    public static void WriteInt16(object ptr, int ofs, short val);

+   /// <safety>Writes through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static void WriteInt32(System.IntPtr ptr, int val);

+   /// <safety>Writes through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static void WriteInt32(System.IntPtr ptr, int ofs, int val);

+   /// <safety>Writes at an unchecked offset inside a pinned object; the offset is not bounds-checked and may fall outside the object</safety>
+   unsafe
    public static void WriteInt32(object ptr, int ofs, int val);

+   /// <safety>Writes through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static void WriteInt64(System.IntPtr ptr, int ofs, long val);

+   /// <safety>Writes through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static void WriteInt64(System.IntPtr ptr, long val);

+   /// <safety>Writes at an unchecked offset inside a pinned object; the offset is not bounds-checked and may fall outside the object</safety>
+   unsafe
    public static void WriteInt64(object ptr, int ofs, long val);

+   /// <safety>Writes through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static void WriteIntPtr(System.IntPtr ptr, int ofs, System.IntPtr val);

+   /// <safety>Writes through a raw, caller-supplied address with no bounds or ownership check</safety>
+   unsafe
    public static void WriteIntPtr(System.IntPtr ptr, System.IntPtr val);

+   /// <safety>Writes at an unchecked offset inside a pinned object; the offset is not bounds-checked and may fall outside the object</safety>
+   unsafe
    public static void WriteIntPtr(object ptr, int ofs, System.IntPtr val);

+   /// <safety>Writes zeros through, then frees, a raw caller-supplied native pointer</safety>
+   unsafe
    public static void ZeroFreeBSTR(System.IntPtr s);

+   /// <safety>Writes zeros through, then frees, a raw caller-supplied native pointer</safety>
+   unsafe
    public static void ZeroFreeCoTaskMemAnsi(System.IntPtr s);

+   /// <safety>Writes zeros through, then frees, a raw caller-supplied native pointer</safety>
+   unsafe
    public static void ZeroFreeCoTaskMemUnicode(System.IntPtr s);

+   /// <safety>Writes zeros through, then frees, a raw caller-supplied native pointer</safety>
+   unsafe
    public static void ZeroFreeCoTaskMemUTF8(System.IntPtr s);

+   /// <safety>Writes zeros through, then frees, a raw caller-supplied native pointer</safety>
+   unsafe
    public static void ZeroFreeGlobalAllocAnsi(System.IntPtr s);

+   /// <safety>Writes zeros through, then frees, a raw caller-supplied native pointer</safety>
+   unsafe
    public static void ZeroFreeGlobalAllocUnicode(System.IntPtr s);
}
namespace System.Runtime.InteropServices;

public abstract class SafeBuffer
{
+   /// <safety>Reinterprets native bytes as a T; T's padding and any pointer/reference fields are produced from raw bytes</safety>
+   unsafe
    public T Read<T>(ulong byteOffset) where T : struct;

+   /// <safety>Reinterprets native bytes as a T[]; T's padding and any pointer/reference fields are produced from raw bytes</safety>
+   unsafe
    public void ReadArray<T>(ulong byteOffset, T[] array, int index, int count) where T : struct;

+   /// <safety>Reinterprets native bytes as a Span<T>; T's padding and any pointer/reference fields are produced from raw bytes</safety>
+   unsafe
    public void ReadSpan<T>(ulong byteOffset, System.Span<T> buffer) where T : struct;

+   /// <safety>Writes T's bytes (including padding) to native memory</safety>
+   unsafe
    public void Write<T>(ulong byteOffset, T value) where T : struct;

+   /// <safety>Writes a T[]'s bytes (including padding) to native memory</safety>
+   unsafe
    public void WriteArray<T>(ulong byteOffset, T[] array, int index, int count) where T : struct;

+   /// <safety>Writes a Span<T>'s bytes (including padding) to native memory</safety>
+   unsafe
    public void WriteSpan<T>(ulong byteOffset, System.ReadOnlySpan<T> data) where T : struct;
}
namespace System.Runtime.InteropServices;

public static partial class SequenceMarshal
{
+   /// <safety>Reinterprets bytes from the reader as an unmanaged T; padding and any embedded pointer fields are produced from raw bytes</safety>
+   unsafe
    public static bool TryRead<T>(ref System.Buffers.SequenceReader<byte> reader, out T value) where T : unmanaged;
}
namespace System.Runtime.InteropServices;

public struct GCHandle
{
+   /// <safety>Builds a handle from a raw, unvalidated address the runtime later dereferences</safety>
+   unsafe
    public static GCHandle FromIntPtr(System.IntPtr value);

+   /// <safety>Wraps a raw, unvalidated handle value</safety>
+   unsafe
    public static explicit operator GCHandle(System.IntPtr value);

+   /// <safety>Frees the handle; GCHandle is a copyable struct, so a double free (or freeing a fabricated/default handle) corrupts the runtime handle table.</safety>
+   unsafe
    public void Free();
}
namespace System.Runtime.InteropServices;

public struct GCHandle<T> where T : class?
{
+   /// <safety>Creates a disposable handle whose Dispose must stay safe, so the constructor carries the burden: the handle (a copyable struct) must be disposed exactly once and never used after disposal, or the handle table is corrupted.</safety>
+   unsafe
    public GCHandle(T target);

+   /// <safety>Builds a handle from a raw, unvalidated address the runtime later dereferences</safety>
+   unsafe
    public static GCHandle<T> FromIntPtr(System.IntPtr value);
}
namespace System.Runtime.InteropServices;

public struct PinnedGCHandle<T> where T : class?
{
+   /// <safety>Creates a disposable handle whose Dispose must stay safe, so the constructor carries the burden: the handle (a copyable struct) must be disposed exactly once and never used after disposal, or the handle table is corrupted.</safety>
+   unsafe
    public PinnedGCHandle(T target);

+   /// <safety>Builds a handle from a raw, unvalidated address the runtime later dereferences</safety>
+   unsafe
    public static PinnedGCHandle<T> FromIntPtr(System.IntPtr value);

+   /// <safety>Stores a new target into the underlying handle; on a default, disposed, or copied-then-disposed handle this writes through an invalid handle slot and corrupts the GC handle table. The getter stays safe.</safety>
+   unsafe
    public T Target { readonly get; set; }
}
namespace System.Runtime.InteropServices;

public struct WeakGCHandle<T> where T : class?
{
+   /// <safety>Creates a disposable handle whose Dispose must stay safe, so the constructor carries the burden: the handle (a copyable struct) must be disposed exactly once and never used after disposal, or the handle table is corrupted.</safety>
+   unsafe
    public WeakGCHandle(T target, bool trackResurrection = false);

+   /// <safety>Builds a handle from a raw, unvalidated address the runtime later dereferences</safety>
+   unsafe
    public static WeakGCHandle<T> FromIntPtr(System.IntPtr value);

+   /// <safety>Stores a new target into the underlying handle; on a default, disposed, or copied-then-disposed handle this writes through an invalid handle slot and corrupts the GC handle table. TryGetTarget (the getter) stays safe.</safety>
+   unsafe
    public readonly void SetTarget(T target);
}
namespace System.Runtime.InteropServices;

public abstract class ComWrappers
{
+   /// <safety>Dereferences a raw, caller-supplied COM (IUnknown) pointer to wrap it</safety>
+   unsafe
    public object GetOrCreateObjectForComInstance(System.IntPtr externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags);

+   /// <safety>Dereferences a raw, caller-supplied COM (IUnknown) pointer to wrap it</safety>
+   unsafe
    public object GetOrCreateObjectForComInstance(System.IntPtr externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags, object? userState);

+   /// <safety>Wraps a raw, caller-supplied COM (IUnknown) pointer that the override dereferences</safety>
+   unsafe
    protected abstract object? CreateObject(System.IntPtr externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags);

+   /// <safety>Wraps a raw, caller-supplied COM (IUnknown) pointer that the override dereferences</safety>
+   unsafe
    protected virtual object? CreateObject(System.IntPtr externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags, object? userState, out System.Runtime.InteropServices.CreatedWrapperFlags wrapperFlags);

+   /// <safety>Dereferences a raw COM (IUnknown) pointer to register it</safety>
+   unsafe
    public object GetOrRegisterObjectForComInstance(System.IntPtr externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags, object wrapper);

+   /// <safety>Dereferences two raw COM (IUnknown) pointers</safety>
+   unsafe
    public object GetOrRegisterObjectForComInstance(System.IntPtr externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags, object wrapper, System.IntPtr inner);
}
namespace System.Runtime.InteropServices;

public partial interface ICustomMarshaler
{
+   /// <safety>Dereferences a raw native-data pointer</safety>
+   unsafe
    void CleanUpNativeData(System.IntPtr pNativeData);

+   /// <safety>Reads through a raw native-data pointer</safety>
+   unsafe
    object MarshalNativeToManaged(System.IntPtr pNativeData);
}
namespace System.Runtime.InteropServices;

public static class ObjectiveCMarshal
{
+   /// <safety>Registers a raw, unvalidated code address the runtime later calls</safety>
+   unsafe
    public static void SetMessageSendCallback(System.Runtime.InteropServices.ObjectiveCMarshal.MessageSendFunction msgSendFunction, System.IntPtr func);
}
namespace System.Runtime.InteropServices.Marshalling;

public struct ComVariant : System.IDisposable
{
+   /// <safety>Stores an unmanaged T's raw bytes into the VARIANT union with no type validation</safety>
+   unsafe
    public static System.Runtime.InteropServices.Marshalling.ComVariant CreateRaw<T>(System.Runtime.InteropServices.VarEnum vt, T rawValue) where T : unmanaged;

+   /// <safety>Reinterprets the VARIANT union bytes as an unmanaged T with no type check</safety>
+   unsafe
    public ref T GetRawDataRef<T>() where T : unmanaged;
}
namespace System.Runtime.InteropServices.ComTypes;

public partial interface IEnumConnectionPoints
{
+   /// <safety>Writes the fetched-element count through a raw caller-supplied pointer</safety>
+   unsafe
    int Next(int celt, System.Runtime.InteropServices.ComTypes.IConnectionPoint[] rgelt, System.IntPtr pceltFetched);
}

public partial interface IEnumConnections
{
+   /// <safety>Writes the fetched-element count through a raw caller-supplied pointer</safety>
+   unsafe
    int Next(int celt, System.Runtime.InteropServices.ComTypes.CONNECTDATA[] rgelt, System.IntPtr pceltFetched);
}

public partial interface IEnumMoniker
{
+   /// <safety>Writes the fetched-element count through a raw caller-supplied pointer</safety>
+   unsafe
    int Next(int celt, System.Runtime.InteropServices.ComTypes.IMoniker[] rgelt, System.IntPtr pceltFetched);
}

public partial interface IEnumString
{
+   /// <safety>Writes the fetched-element count through a raw caller-supplied pointer</safety>
+   unsafe
    int Next(int celt, string[] rgelt, System.IntPtr pceltFetched);
}

public partial interface IEnumVARIANT
{
+   /// <safety>Writes the fetched-element count through a raw caller-supplied pointer</safety>
+   unsafe
    int Next(int celt, object?[] rgVar, System.IntPtr pceltFetched);
}

public partial interface IStream
{
+   /// <safety>Writes the bytes-read and bytes-written counts through raw caller-supplied pointers</safety>
+   unsafe
    void CopyTo(System.Runtime.InteropServices.ComTypes.IStream pstm, long cb, System.IntPtr pcbRead, System.IntPtr pcbWritten);

+   /// <safety>Writes the bytes-read count through a raw caller-supplied pointer</safety>
+   unsafe
    void Read(byte[] pv, int cb, System.IntPtr pcbRead);

+   /// <safety>Writes the new stream position through a raw caller-supplied pointer</safety>
+   unsafe
    void Seek(long dlibMove, int dwOrigin, System.IntPtr plibNewPosition);

+   /// <safety>Writes the bytes-written count through a raw caller-supplied pointer</safety>
+   unsafe
    void Write(byte[] pv, int cb, System.IntPtr pcbWritten);
}

public partial interface ITypeInfo
{
+   /// <safety>Writes the DLL name, entry name, and ordinal results through raw caller-supplied pointers</safety>
+   unsafe
    void GetDllEntry(int memid, System.Runtime.InteropServices.ComTypes.INVOKEKIND invKind, System.IntPtr pBstrDllName, System.IntPtr pBstrName, System.IntPtr pwOrdinal);

+   /// <safety>Writes the invocation result and exception info through raw caller-supplied pointers</safety>
+   unsafe
    void Invoke(object pvInstance, int memid, short wFlags, ref System.Runtime.InteropServices.ComTypes.DISPPARAMS pDispParams, System.IntPtr pVarResult, System.IntPtr pExcepInfo, out int puArgErr);

+   /// <safety>Frees a native FUNCDESC through a raw caller-supplied pointer</safety>
+   unsafe
    void ReleaseFuncDesc(System.IntPtr pFuncDesc);

+   /// <safety>Frees a native TYPEATTR through a raw caller-supplied pointer</safety>
+   unsafe
    void ReleaseTypeAttr(System.IntPtr pTypeAttr);

+   /// <safety>Frees a native VARDESC through a raw caller-supplied pointer</safety>
+   unsafe
    void ReleaseVarDesc(System.IntPtr pVarDesc);
}

public partial interface ITypeInfo2
{
+   /// <safety>Writes a CUSTDATA structure through a raw caller-supplied pointer</safety>
+   unsafe
    void GetAllCustData(System.IntPtr pCustData);

+   /// <safety>Writes a CUSTDATA structure through a raw caller-supplied pointer</safety>
+   unsafe
    void GetAllFuncCustData(int index, System.IntPtr pCustData);

+   /// <safety>Writes a CUSTDATA structure through a raw caller-supplied pointer</safety>
+   unsafe
    void GetAllImplTypeCustData(int index, System.IntPtr pCustData);

+   /// <safety>Writes a CUSTDATA structure through a raw caller-supplied pointer</safety>
+   unsafe
    void GetAllParamCustData(int indexFunc, int indexParam, System.IntPtr pCustData);

+   /// <safety>Writes a CUSTDATA structure through a raw caller-supplied pointer</safety>
+   unsafe
    void GetAllVarCustData(int index, System.IntPtr pCustData);
}

public partial interface ITypeLib
{
+   /// <safety>Frees a native TLIBATTR through a raw caller-supplied pointer</safety>
+   unsafe
    void ReleaseTLibAttr(System.IntPtr pTLibAttr);
}

public partial interface ITypeLib2
{
+   /// <safety>Writes a CUSTDATA structure through a raw caller-supplied pointer</safety>
+   unsafe
    void GetAllCustData(System.IntPtr pCustData);

+   /// <safety>Writes a count through a raw caller-supplied pointer</safety>
+   unsafe
    void GetLibStatistics(System.IntPtr pcUniqueNames, out int pcchUniqueNames);

+   /// <safety>Frees a native TLIBATTR through a raw caller-supplied pointer</safety>
+   unsafe
    void ReleaseTLibAttr(System.IntPtr pTLibAttr);
}

Note: UnsafeAddrOfPinnedArrayElement (returns an address only) and the generic-handle
members GCHandle<T>.Target, PinnedGCHandle<T>.Target, WeakGCHandle<T>.TryGetTarget
(gated by the already-unsafe FromIntPtr entry points) are flagged for possible exclusion;
see the review's exclude.md.

API Usage

The annotated APIs will require unsafe { } context at their call site once the language-level unsafe requirement is enforced.

Alternative Designs

No response

Risks

No response

Activity

  1. added
    api-suggestion
    on Jun 23, 2026
  2. added
    untriaged
    on Jun 23, 2026
  3. dotnet-policy-service commented on Jun 23, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/interop-contrib
    See info in area-owners.md if you want to be subscribed.

  4. AaronRobinsonMSFT commented on Jun 23, 2026

    @AaronRobinsonMSFT
    Member

    @EgorBo Some more Marshal APIs to consider.

    These are implicitly constructing RCWs, so they may flow naturally from the implementation. I think they will be marked unsafe in practice.

    BindToMoniker
    CreateWrapperOfType

    These all dereference the pointer and write to it.

    ZeroFreeBSTR
    ZeroFreeCoTaskMemAnsi
    ZeroFreeCoTaskMemUnicode
    ZeroFreeCoTaskMemUTF8
    ZeroFreeGlobalAllocAnsi
    ZeroFreeGlobalAllocUnicode

  5. added
    api-ready-for-review
    and removed
    api-suggestion
    untriaged
    on Jun 23, 2026
  6. added this to the 11.0.0 milestone on Jun 23, 2026
  7. bartonjs commented on Jul 30, 2026

    @bartonjs
    Member

    Video

    • For the IDisposable GCHandle types, consider explicitly implementing IDisposable.Dispose and making public void Dispose be unsafe, so the alloc (ctor) and free (Dispose) are both unsafe (assuming a strong typeref).
      • Especially because value-copied (or box-copied) versions of the GCHandle type can cause a double free.
    • Otherwise, looks good as proposed.
    namespace System.Runtime.InteropServices.Marshalling
    {
        public partial class StrategyBasedComWrappers : System.Runtime.InteropServices.ComWrappers
        {
            protected sealed override object CreateObject(nint externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags);
    
    +       unsafe
            protected sealed override object? CreateObject(nint externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags, object? userState, out System.Runtime.InteropServices.CreatedWrapperFlags wrapperFlags);
    }
    
    namespace System.IO
    {
        public partial class UnmanagedMemoryAccessor : System.IDisposable
        {
    +       unsafe
            public int ReadArray<T>(long position, T[] array, int offset, int count) where T : struct;
    
    +       unsafe
            public void Read<T>(long position, out T structure) where T : struct;
    
    +       unsafe
            public void WriteArray<T>(long position, T[] array, int offset, int count) where T : struct;
    
    +       unsafe
            public void Write<T>(long position, ref T structure) where T : struct;
        }
    }
    
    namespace System.Runtime.InteropServices
    {
        public static partial class Marshal
        {
    +       unsafe
            public static int AddRef(System.IntPtr pUnk);
    
    +       unsafe
            public static System.IntPtr CreateAggregatedObject(System.IntPtr pOuter, object o);
    
    +       unsafe
            public static System.IntPtr CreateAggregatedObject<T>(System.IntPtr pOuter, T o) where T : notnull;
    
    +       unsafe
            public static void Copy(byte[] source, int startIndex, System.IntPtr destination, int length);
    
    +       unsafe
            public static void Copy(char[] source, int startIndex, System.IntPtr destination, int length);
    
    +       unsafe
            public static void Copy(double[] source, int startIndex, System.IntPtr destination, int length);
    
    +       unsafe
            public static void Copy(short[] source, int startIndex, System.IntPtr destination, int length);
    
    +       unsafe
            public static void Copy(int[] source, int startIndex, System.IntPtr destination, int length);
    
    +       unsafe
            public static void Copy(long[] source, int startIndex, System.IntPtr destination, int length);
    
    +       unsafe
            public static void Copy(System.IntPtr source, byte[] destination, int startIndex, int length);
    
    +       unsafe
            public static void Copy(System.IntPtr source, char[] destination, int startIndex, int length);
    
    +       unsafe
            public static void Copy(System.IntPtr source, double[] destination, int startIndex, int length);
    
    +       unsafe
            public static void Copy(System.IntPtr source, short[] destination, int startIndex, int length);
    
    +       unsafe
            public static void Copy(System.IntPtr source, int[] destination, int startIndex, int length);
    
    +       unsafe
            public static void Copy(System.IntPtr source, long[] destination, int startIndex, int length);
    
    +       unsafe
            public static void Copy(System.IntPtr source, System.IntPtr[] destination, int startIndex, int length);
    
    +       unsafe
            public static void Copy(System.IntPtr source, float[] destination, int startIndex, int length);
    
    +       unsafe
            public static void Copy(System.IntPtr[] source, int startIndex, System.IntPtr destination, int length);
    
    +       unsafe
            public static void Copy(float[] source, int startIndex, System.IntPtr destination, int length);
    
    +       unsafe
            public static void DestroyStructure(System.IntPtr ptr, System.Type structuretype);
    
    +       unsafe
            public static void DestroyStructure<T>(System.IntPtr ptr);
    
    +       unsafe
            public static void FreeBSTR(System.IntPtr ptr);
    
    +       unsafe
            public static void FreeCoTaskMem(System.IntPtr ptr);
    
    +       unsafe
            public static void FreeHGlobal(System.IntPtr hglobal);
    
    +       unsafe
            public static System.Delegate GetDelegateForFunctionPointer(System.IntPtr ptr, System.Type t);
    
    +       unsafe
            public static TDelegate GetDelegateForFunctionPointer<TDelegate>(System.IntPtr ptr);
    
    +       unsafe
            public static System.Exception? GetExceptionForHR(int errorCode, System.IntPtr errorInfo);
    
    +       unsafe
            public static System.Exception? GetExceptionForHR(int errorCode, in System.Guid iid, System.IntPtr pUnk);
    
    +       unsafe
            public static void GetNativeVariantForObject(object? obj, System.IntPtr pDstNativeVariant);
    
    +       unsafe
            public static void GetNativeVariantForObject<T>(T? obj, System.IntPtr pDstNativeVariant);
    
    +       unsafe
            public static object GetObjectForIUnknown(System.IntPtr pUnk);
    
    +       unsafe
            public static object? GetObjectForNativeVariant(System.IntPtr pSrcNativeVariant);
    
    +       unsafe
            public static T? GetObjectForNativeVariant<T>(System.IntPtr pSrcNativeVariant);
    
    +       unsafe
            public static object?[] GetObjectsForNativeVariants(System.IntPtr aSrcNativeVariant, int cVars);
    
    +       unsafe
            public static T[] GetObjectsForNativeVariants<T>(System.IntPtr aSrcNativeVariant, int cVars);
    
    +       unsafe
            public static object GetTypedObjectForIUnknown(System.IntPtr pUnk, System.Type t);
    
    +       unsafe
            public static object GetUniqueObjectForIUnknown(System.IntPtr unknown);
    
    +       unsafe
            public static string? PtrToStringAnsi(System.IntPtr ptr);
    
    +       unsafe
            public static string PtrToStringAnsi(System.IntPtr ptr, int len);
    
    +       unsafe
            public static string? PtrToStringAuto(System.IntPtr ptr);
    
    +       unsafe
            public static string? PtrToStringAuto(System.IntPtr ptr, int len);
    
    +       unsafe
            public static string PtrToStringBSTR(System.IntPtr ptr);
    
    +       unsafe
            public static string? PtrToStringUni(System.IntPtr ptr);
    
    +       unsafe
            public static string PtrToStringUni(System.IntPtr ptr, int len);
    
    +       unsafe
            public static string? PtrToStringUTF8(System.IntPtr ptr);
    
    +       unsafe
            public static string PtrToStringUTF8(System.IntPtr ptr, int byteLen);
    
    +       unsafe
            public static void PtrToStructure(System.IntPtr ptr, object structure);
    
    +       unsafe
            public static object? PtrToStructure(System.IntPtr ptr, System.Type structureType);
    
    +       unsafe
            public static T? PtrToStructure<T>(System.IntPtr ptr);
    
    +       unsafe
            public static void PtrToStructure<T>(System.IntPtr ptr, T structure);
    
    +       unsafe
            public static int QueryInterface(System.IntPtr pUnk, in System.Guid iid, out System.IntPtr ppv);
    
    +       unsafe
            public static byte ReadByte(System.IntPtr ptr);
    
    +       unsafe
            public static byte ReadByte(System.IntPtr ptr, int ofs);
    
    +       unsafe
            public static byte ReadByte(object ptr, int ofs);
    
    +       unsafe
            public static short ReadInt16(System.IntPtr ptr);
    
    +       unsafe
            public static short ReadInt16(System.IntPtr ptr, int ofs);
    
    +       unsafe
            public static short ReadInt16(object ptr, int ofs);
    
    +       unsafe
            public static int ReadInt32(System.IntPtr ptr);
    
    +       unsafe
            public static int ReadInt32(System.IntPtr ptr, int ofs);
    
    +       unsafe
            public static int ReadInt32(object ptr, int ofs);
    
    +       unsafe
            public static long ReadInt64(System.IntPtr ptr);
    
    +       unsafe
            public static long ReadInt64(System.IntPtr ptr, int ofs);
    
    +       unsafe
            public static long ReadInt64(object ptr, int ofs);
    
    +       unsafe
            public static System.IntPtr ReadIntPtr(System.IntPtr ptr);
    
    +       unsafe
            public static System.IntPtr ReadIntPtr(System.IntPtr ptr, int ofs);
    
    +       unsafe
            public static System.IntPtr ReadIntPtr(object ptr, int ofs);
    
    +       unsafe
            public static System.IntPtr ReAllocCoTaskMem(System.IntPtr pv, int cb);
    
    +       unsafe
            public static System.IntPtr ReAllocHGlobal(System.IntPtr pv, System.IntPtr cb);
    
    +       unsafe
            public static int Release(System.IntPtr pUnk);
    
    +       unsafe
            public static void StructureToPtr(object structure, System.IntPtr ptr, bool fDeleteOld);
    
    +       unsafe
            public static void StructureToPtr<T>(T structure, System.IntPtr ptr, bool fDeleteOld);
    
    +       unsafe
            public static void ThrowExceptionForHR(int errorCode, System.IntPtr errorInfo);
    
    +       unsafe
            public static void ThrowExceptionForHR(int errorCode, in System.Guid iid, System.IntPtr pUnk);
    
    +       unsafe
            public static void WriteByte(System.IntPtr ptr, byte val);
    
    +       unsafe
            public static void WriteByte(System.IntPtr ptr, int ofs, byte val);
    
    +       unsafe
            public static void WriteByte(object ptr, int ofs, byte val);
    
    +       unsafe
            public static void WriteInt16(System.IntPtr ptr, char val);
    
    +       unsafe
            public static void WriteInt16(System.IntPtr ptr, short val);
    
    +       unsafe
            public static void WriteInt16(System.IntPtr ptr, int ofs, char val);
    
    +       unsafe
            public static void WriteInt16(System.IntPtr ptr, int ofs, short val);
    
    +       unsafe
            public static void WriteInt16(object ptr, int ofs, char val);
    
    +       unsafe
            public static void WriteInt16(object ptr, int ofs, short val);
    
    +       unsafe
            public static void WriteInt32(System.IntPtr ptr, int val);
    
    +       unsafe
            public static void WriteInt32(System.IntPtr ptr, int ofs, int val);
    
    +       unsafe
            public static void WriteInt32(object ptr, int ofs, int val);
    
    +       unsafe
            public static void WriteInt64(System.IntPtr ptr, int ofs, long val);
    
    +       unsafe
            public static void WriteInt64(System.IntPtr ptr, long val);
    
    +       unsafe
            public static void WriteInt64(object ptr, int ofs, long val);
    
    +       unsafe
            public static void WriteIntPtr(System.IntPtr ptr, int ofs, System.IntPtr val);
    
    +       unsafe
            public static void WriteIntPtr(System.IntPtr ptr, System.IntPtr val);
    
    +       unsafe
            public static void WriteIntPtr(object ptr, int ofs, System.IntPtr val);
    
    +       unsafe
            public static void ZeroFreeBSTR(System.IntPtr s);
    
    +       unsafe
            public static void ZeroFreeCoTaskMemAnsi(System.IntPtr s);
    
    +       unsafe
            public static void ZeroFreeCoTaskMemUnicode(System.IntPtr s);
    
    +       unsafe
            public static void ZeroFreeCoTaskMemUTF8(System.IntPtr s);
    
    +       unsafe
            public static void ZeroFreeGlobalAllocAnsi(System.IntPtr s);
    
    +       unsafe
            public static void ZeroFreeGlobalAllocUnicode(System.IntPtr s);
        }
    
        public abstract class SafeBuffer
        {
    +       unsafe
            public T Read<T>(ulong byteOffset) where T : struct;
    
    +       unsafe
            public void ReadArray<T>(ulong byteOffset, T[] array, int index, int count) where T : struct;
    
    +       unsafe
            public void ReadSpan<T>(ulong byteOffset, System.Span<T> buffer) where T : struct;
    
    +       unsafe
            public void Write<T>(ulong byteOffset, T value) where T : struct;
    
    +       unsafe
            public void WriteArray<T>(ulong byteOffset, T[] array, int index, int count) where T : struct;
    
    +       unsafe
            public void WriteSpan<T>(ulong byteOffset, System.ReadOnlySpan<T> data) where T : struct;
        }
    
        public static partial class SequenceMarshal
        {
    +       unsafe
            public static bool TryRead<T>(ref System.Buffers.SequenceReader<byte> reader, out T value) where T : unmanaged;
        }
    
        public struct GCHandle
        {
    +       unsafe
            public static GCHandle FromIntPtr(System.IntPtr value);
    
    +       unsafe
            public static explicit operator GCHandle(System.IntPtr value);
    
    +       unsafe
            public void Free();
        }
    
        public struct GCHandle<T> where T : class?
        {
    +       unsafe
            public GCHandle(T target);
    
    +       unsafe
            public static GCHandle<T> FromIntPtr(System.IntPtr value);
        }
    
        public struct PinnedGCHandle<T> where T : class?
        {
    +       unsafe
            public PinnedGCHandle(T target);
    
    +       unsafe
            public static PinnedGCHandle<T> FromIntPtr(System.IntPtr value);
    
    +       unsafe
            public T Target { readonly get; set; }
        }
    
        public struct WeakGCHandle<T> where T : class?
        {
    +       unsafe
            public WeakGCHandle(T target, bool trackResurrection = false);
    
    +       unsafe
            public static WeakGCHandle<T> FromIntPtr(System.IntPtr value);
    
    +       unsafe
            public readonly void SetTarget(T target);
        }
    
        public abstract class ComWrappers
        {
    +       unsafe
            public object GetOrCreateObjectForComInstance(System.IntPtr externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags);
    
    +       unsafe
            public object GetOrCreateObjectForComInstance(System.IntPtr externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags, object? userState);
    
    +       unsafe
            protected abstract object? CreateObject(System.IntPtr externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags);
    
    +       unsafe
            protected virtual object? CreateObject(System.IntPtr externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags, object? userState, out System.Runtime.InteropServices.CreatedWrapperFlags wrapperFlags);
    
    +       unsafe
            public object GetOrRegisterObjectForComInstance(System.IntPtr externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags, object wrapper);
    
    +       unsafe
            public object GetOrRegisterObjectForComInstance(System.IntPtr externalComObject, System.Runtime.InteropServices.CreateObjectFlags flags, object wrapper, System.IntPtr inner);
        }
    
        public partial interface ICustomMarshaler
        {
    +       unsafe
            void CleanUpNativeData(System.IntPtr pNativeData);
    
    +       unsafe
            object MarshalNativeToManaged(System.IntPtr pNativeData);
        }
    
        public static class ObjectiveCMarshal
        {
    +       unsafe
            public static void SetMessageSendCallback(System.Runtime.InteropServices.ObjectiveCMarshal.MessageSendFunction msgSendFunction, System.IntPtr func);
        }
    }
    
    namespace System.Runtime.InteropServices.Marshalling
    {
        public struct ComVariant : System.IDisposable
        {
    +       unsafe
            public static System.Runtime.InteropServices.Marshalling.ComVariant CreateRaw<T>(System.Runtime.InteropServices.VarEnum vt, T rawValue) where T : unmanaged;
    
    +       unsafe
            public ref T GetRawDataRef<T>() where T : unmanaged;
        }
    }
    
    namespace System.Runtime.InteropServices.ComTypes
    {
        public partial interface IEnumConnectionPoints
        {
    +       unsafe
            int Next(int celt, System.Runtime.InteropServices.ComTypes.IConnectionPoint[] rgelt, System.IntPtr pceltFetched);
        }
    
        public partial interface IEnumConnections
        {
    +       unsafe
            int Next(int celt, System.Runtime.InteropServices.ComTypes.CONNECTDATA[] rgelt, System.IntPtr pceltFetched);
        }
    
        public partial interface IEnumMoniker
        {
    +       unsafe
            int Next(int celt, System.Runtime.InteropServices.ComTypes.IMoniker[] rgelt, System.IntPtr pceltFetched);
        }
    
        public partial interface IEnumString
        {
    +       unsafe
            int Next(int celt, string[] rgelt, System.IntPtr pceltFetched);
        }
    
        public partial interface IEnumVARIANT
        {
    +       unsafe
            int Next(int celt, object?[] rgVar, System.IntPtr pceltFetched);
        }
    
        public partial interface IStream
        {
    +       unsafe
            void CopyTo(System.Runtime.InteropServices.ComTypes.IStream pstm, long cb, System.IntPtr pcbRead, System.IntPtr pcbWritten);
    
    +       unsafe
            void Read(byte[] pv, int cb, System.IntPtr pcbRead);
    
    +       unsafe
            void Seek(long dlibMove, int dwOrigin, System.IntPtr plibNewPosition);
    
    +       unsafe
            void Write(byte[] pv, int cb, System.IntPtr pcbWritten);
        }
    
        public partial interface ITypeInfo
        {
    +       unsafe
            void GetDllEntry(int memid, System.Runtime.InteropServices.ComTypes.INVOKEKIND invKind, System.IntPtr pBstrDllName, System.IntPtr pBstrName, System.IntPtr pwOrdinal);
    
    +       unsafe
            void Invoke(object pvInstance, int memid, short wFlags, ref System.Runtime.InteropServices.ComTypes.DISPPARAMS pDispParams, System.IntPtr pVarResult, System.IntPtr pExcepInfo, out int puArgErr);
    
    +       unsafe
            void ReleaseFuncDesc(System.IntPtr pFuncDesc);
    
    +       unsafe
            void ReleaseTypeAttr(System.IntPtr pTypeAttr);
    
    +       unsafe
            void ReleaseVarDesc(System.IntPtr pVarDesc);
        }
    
        public partial interface ITypeInfo2
        {
    +       unsafe
            void GetAllCustData(System.IntPtr pCustData);
    
    +       unsafe
            void GetAllFuncCustData(int index, System.IntPtr pCustData);
    
    +       unsafe
            void GetAllImplTypeCustData(int index, System.IntPtr pCustData);
    
    +       unsafe
            void GetAllParamCustData(int indexFunc, int indexParam, System.IntPtr pCustData);
    
    +       unsafe
            void GetAllVarCustData(int index, System.IntPtr pCustData);
        }
    
        public partial interface ITypeLib
        {
    +       unsafe
            void ReleaseTLibAttr(System.IntPtr pTLibAttr);
        }
    
        public partial interface ITypeLib2
        {
    +       unsafe
            void GetAllCustData(System.IntPtr pCustData);
    
    +       unsafe
            void GetLibStatistics(System.IntPtr pcUniqueNames, out int pcchUniqueNames);
    
    +       unsafe
            void ReleaseTLibAttr(System.IntPtr pTLibAttr);
        }
    }
  8. added
    api-approved
    and removed
    api-ready-for-review
    on Jul 30, 2026
  9. agocke commented on Aug 14, 2026

    @agocke
    Member

    Fixed by #131733

  10. locked and limited conversation to collaborators on Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedarea-System.Runtime.InteropServicesreduce-unsafe

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions