Check GenerateGuidForType argument for null (#21851)
authorStephen Toub <stoub@microsoft.com>
Tue, 8 Jan 2019 00:22:14 +0000 (19:22 -0500)
committerAaron Robinson <arobins@microsoft.com>
Tue, 8 Jan 2019 00:22:14 +0000 (16:22 -0800)
* Check GenerateGuidForType argument for null

* Also check for RuntimeType

src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs

index ff9844e..ed3d648 100644 (file)
@@ -1540,7 +1540,19 @@ namespace System.Runtime.InteropServices
         /// metadata then it is returned otherwise a stable guid is generated based
         /// on the fully qualified name of the type.
         /// </summary>
-        public static Guid GenerateGuidForType(Type type) => type.GUID;
+        public static Guid GenerateGuidForType(Type type)
+        {
+            if (type == null)
+            {
+                throw new ArgumentNullException(nameof(type));
+            }
+            if (!(type is RuntimeType))
+            {
+                throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(type));
+            }
+
+            return type.GUID;
+        }
 
         /// <summary>
         /// This method generates a PROGID for the specified type. If the type has