From 87e96eafa84545335dd6ec02cb4e233211456677 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 28 Sep 2018 23:37:34 -0700 Subject: [PATCH] Unify argument verification for Marshal.GetHINSTANCE off-Windows (#20130) --- src/System.Private.CoreLib/Resources/Strings.resx | 3 --- .../src/System/Runtime/InteropServices/Marshal.cs | 12 +++--------- tests/CoreFX/CoreFX.issues.json | 4 ++++ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/System.Private.CoreLib/Resources/Strings.resx b/src/System.Private.CoreLib/Resources/Strings.resx index 30c3831..26f5b66 100644 --- a/src/System.Private.CoreLib/Resources/Strings.resx +++ b/src/System.Private.CoreLib/Resources/Strings.resx @@ -1294,9 +1294,6 @@ MethodInfo must be a runtime MethodInfo object. - - Module must be a runtime Module object. - The object must be a runtime Reflection object. diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs index c4c65da..d7d5b0f 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs @@ -853,18 +853,12 @@ namespace System.Runtime.InteropServices throw new ArgumentNullException(nameof(m)); } - RuntimeModule rtModule = m as RuntimeModule; - if (rtModule == null && m is ModuleBuilder mb) + if (m is RuntimeModule rtModule) { - rtModule = mb.InternalModule; + return GetHINSTANCE(rtModule.GetNativeHandle()); } - if (rtModule == null) - { - throw new ArgumentNullException(nameof(m), SR.Argument_MustBeRuntimeModule); - } - - return GetHINSTANCE(rtModule.GetNativeHandle()); + return (IntPtr)(-1); } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] diff --git a/tests/CoreFX/CoreFX.issues.json b/tests/CoreFX/CoreFX.issues.json index 580a636..9398076 100644 --- a/tests/CoreFX/CoreFX.issues.json +++ b/tests/CoreFX/CoreFX.issues.json @@ -415,6 +415,10 @@ "classes": null, "methods": [ { + "name": "System.Runtime.InteropServices.Tests.GetHINSTANCETests.GetHINSTANCE_NonRuntimeModule_ThrowsArgumentNullException", + "reason": "https://github.com/dotnet/coreclr/pull/30925" + }, + { "name" : "System.Runtime.InteropServices.Tests.SafeBufferTests.Initialize_NumBytesTimesSizeOfEachElement_ThrowsOverflowException", "reason" : "https://github.com/dotnet/coreclr/pull/20132" }, -- 2.7.4