diff --git a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs index 6d9c3d7680f31..3c9c08b7c0e81 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs @@ -802,17 +802,19 @@ internal static unsafe void ConvertContentsToNative(ICustomMarshaler marshaler, // COMPAT: We never pass null to MarshalManagedToNative. if (pManagedHome is null) { + *pNativeHome = IntPtr.Zero; return; } *pNativeHome = marshaler.MarshalManagedToNative(pManagedHome); } - internal static void ConvertContentsToManaged(ICustomMarshaler marshaler, ref object pManagedHome, IntPtr* pNativeHome) + internal static void ConvertContentsToManaged(ICustomMarshaler marshaler, ref object? pManagedHome, IntPtr* pNativeHome) { // COMPAT: We never pass null to MarshalNativeToManaged. if (*pNativeHome == IntPtr.Zero) { + pManagedHome = null; return; }