diff --git a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs index 4d04557565c3c..2d379d4326c88 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs @@ -807,17 +807,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; }