-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
Description
Today, the SafeHandle marshaler prohibits null SafeHandle instances:
runtime/src/coreclr/src/System.Private.CoreLib/src/System/StubHelpers.cs
Lines 1251 to 1256 in e489111
| internal static IntPtr SafeHandleAddRef(SafeHandle pHandle, ref bool success) | |
| { | |
| if (pHandle == null) | |
| { | |
| ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pHandle, ExceptionResource.ArgumentNull_SafeHandle); | |
| } |
but there are native methods that let you pass a null pointer to mean "I don't have one". To call such methods, you then either need to use an IntPtr directly or have multiple P/Invoke definitions (one for when you have a non-null SafeHandle and one for when you have null) or create a throw-away safe handle instance that contains IntPtr.Zero. It's not clear to me why the marshaler prohibits null; it could just marshal it as null / zero.
AaronRobinsonMSFT, geoffkizer, omariom, Mrnikbobjeff and GSPP
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status