ReflectionOnlyLoad should throw NotSupportedException (dotnet/coreclr#9238)
authorRahul Kumar <rahku@microsoft.com>
Wed, 1 Feb 2017 06:13:36 +0000 (22:13 -0800)
committerJan Kotas <jkotas@microsoft.com>
Wed, 1 Feb 2017 06:13:36 +0000 (22:13 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/4ee30cce27492510ac115b2076a79310edface6c

src/coreclr/src/mscorlib/src/System.Private.CoreLib.txt
src/coreclr/src/mscorlib/src/System/Reflection/Assembly.cs
src/coreclr/src/mscorlib/src/System/Type.cs

index 43d9a74..5fad0bd 100644 (file)
@@ -1389,6 +1389,8 @@ NotSupported_AssemblyLoadCodeBase = Assembly.Load with a Codebase is not support
 NotSupported_AssemblyLoadFromHash = Assembly.LoadFrom with hashValue is not supported.
 NotSupported_CannotCallEqualsOnSpan = Equals() on Span and ReadOnlySpan is not supported. Use operator== instead.
 NotSupported_CannotCallGetHashCodeOnSpan = GetHashCode() on Span and ReadOnlySpan is not supported.
+NotSupported_ReflectionOnlyLoad = Assembly.ReflectionOnlyLoad is not supported.
+NotSupported_ReflectionOnlyGetType = Type.ReflectionOnlyGetType is not supported.
 
 ; TypeLoadException
 TypeLoad_ResolveType = Could not resolve type '{0}'.
index f8cb3b6..22b47c5 100644 (file)
@@ -112,18 +112,11 @@ namespace System.Reflection
         [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
         public static Assembly ReflectionOnlyLoadFrom(String assemblyFile)
         {
-            Contract.Ensures(Contract.Result<Assembly>() != null);
-
-            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
-
-            return RuntimeAssembly.InternalLoadFrom(
-                assemblyFile,
-                null, //securityEvidence
-                null, //hashValue
-                AssemblyHashAlgorithm.None,
-                true,  //forIntrospection
-                false, //suppressSecurityChecks
-                ref stackMark);
+            if (assemblyFile == null)
+                throw new ArgumentNullException(nameof(assemblyFile));
+            if (assemblyFile.Length == 0)
+                throw new ArgumentException(Environment.GetResourceString("Format_StringZeroLength"));
+            throw new NotSupportedException(Environment.GetResourceString("NotSupported_ReflectionOnlyLoad"));
         }
 
         // Evidence is protected in Assembly.Load()
@@ -229,10 +222,11 @@ namespace System.Reflection
         [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
         public static Assembly ReflectionOnlyLoad(String assemblyString)
         {
-            Contract.Ensures(Contract.Result<Assembly>() != null);
-
-            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
-            return RuntimeAssembly.InternalLoad(assemblyString, null,  ref stackMark, true /*forIntrospection*/);
+            if (assemblyString == null)
+                throw new ArgumentNullException(nameof(assemblyString));
+            if (assemblyString.Length == 0)
+                throw new ArgumentException(Environment.GetResourceString("Format_StringZeroLength"));
+            throw new NotSupportedException(Environment.GetResourceString("NotSupported_ReflectionOnlyLoad"));
         }
     
         [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
@@ -319,18 +313,9 @@ namespace System.Reflection
         [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
         public static Assembly ReflectionOnlyLoad(byte[] rawAssembly)
         {
-            Contract.Ensures(Contract.Result<Assembly>() != null);
-
-            AppDomain.CheckReflectionOnlyLoadSupported();
-
-            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
-            return RuntimeAssembly.nLoadImage(
-                rawAssembly,
-                null, // symbol store
-                null, // evidence
-                ref stackMark,
-                true,  // fIntrospection
-                SecurityContextSource.CurrentAssembly);
+            if (rawAssembly == null)
+                throw new ArgumentNullException(nameof(rawAssembly));
+            throw new NotSupportedException(Environment.GetResourceString("NotSupported_ReflectionOnlyLoad"));
         }
 
         // Loads the assembly with a COFF based IMAGE containing
index 2d30c4c..2b6e048 100644 (file)
@@ -135,8 +135,11 @@ namespace System
         [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
         public static Type ReflectionOnlyGetType(String typeName, bool throwIfNotFound, bool ignoreCase) 
         {
-            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
-            return RuntimeType.GetType(typeName, throwIfNotFound, ignoreCase, true /*reflectionOnly*/, ref stackMark);
+            if (typeName == null)
+                throw new ArgumentNullException(nameof(typeName));
+            if (typeName.Length == 0 && throwIfNotFound)
+                throw new TypeLoadException(Environment.GetResourceString("Arg_TypeLoadNullStr"));
+            throw new NotSupportedException(Environment.GetResourceString("NotSupported_ReflectionOnlyGetType"));
         }
 
         public virtual Type MakePointerType() { throw new NotSupportedException(); }