Unify argument verification for Marshal.GetHINSTANCE off-Windows (dotnet/coreclr...
authorJeremy Koritzinsky <jkoritzinsky@gmail.com>
Sat, 29 Sep 2018 06:37:34 +0000 (23:37 -0700)
committerJan Kotas <jkotas@microsoft.com>
Sat, 29 Sep 2018 06:37:34 +0000 (23:37 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/87e96eafa84545335dd6ec02cb4e233211456677

src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs
src/coreclr/tests/CoreFX/CoreFX.issues.json

index 30c3831..26f5b66 100644 (file)
   <data name="Argument_MustBeRuntimeMethodInfo" xml:space="preserve">
     <value>MethodInfo must be a runtime MethodInfo object.</value>
   </data>
-  <data name="Argument_MustBeRuntimeModule" xml:space="preserve">
-    <value>Module must be a runtime Module object.</value>
-  </data>
   <data name="Argument_MustBeRuntimeReflectionObject" xml:space="preserve">
     <value>The object must be a runtime Reflection object.</value>
   </data>
index c4c65da..d7d5b0f 100644 (file)
@@ -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)]
index 580a636..9398076 100644 (file)
             "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"
                 },