Remove create assembly name (#24154)
authorSteve MacLean <stmaclea@microsoft.com>
Mon, 22 Apr 2019 14:07:13 +0000 (10:07 -0400)
committerJan Kotas <jkotas@microsoft.com>
Mon, 22 Apr 2019 14:07:13 +0000 (07:07 -0700)
* Remove RuntimeAssembly.CreateAssemblyName

Fixes #24135

CreateAssemblyName was not compatible with AssemblyLoadContext isolation.

Assembly.Load(string)
Assembly.LoadWithPartialName(string)
Activator.CreateInstance(...)

* Remove unused AssemblyNameNative::Init arguments

* Temp disable corefx CreateInstanceAssemblyResolve

src/System.Private.CoreLib/shared/System/Activator.RuntimeType.cs
src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs
src/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs
src/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs
src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
src/vm/assemblyname.cpp
src/vm/assemblyname.hpp
tests/CoreFX/CoreFX.issues.json

index cc4ef6f..1db47ee 100644 (file)
@@ -112,14 +112,9 @@ namespace System
             }
             else
             {
-                RuntimeAssembly? assemblyFromResolveEvent;
-                AssemblyName assemblyName = RuntimeAssembly.CreateAssemblyName(assemblyString, out assemblyFromResolveEvent);
-                if (assemblyFromResolveEvent != null)
-                {
-                    // Assembly was resolved via AssemblyResolve event
-                    assembly = assemblyFromResolveEvent;
-                }
-                else if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
+                AssemblyName assemblyName = new AssemblyName(assemblyString);
+
+                if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
                 {
                     // WinRT type - we have to use Type.GetType
                     type = Type.GetType(typeName + ", " + assemblyString, true /*throwOnError*/, ignoreCase);
index 1e9699f..4722ed3 100644 (file)
@@ -199,25 +199,6 @@ namespace System.Reflection
 
         public static Assembly Load(byte[] rawAssembly) => Load(rawAssembly, rawSymbolStore: null);
 
-        [Obsolete("This method has been deprecated. Please use Assembly.Load() instead. https://go.microsoft.com/fwlink/?linkid=14202")]
-        public static Assembly LoadWithPartialName(string partialName)
-        {
-            if (partialName == null)
-                throw new ArgumentNullException(nameof(partialName));
-
-            if ((partialName.Length == 0) || (partialName[0] == '\0'))
-                throw new ArgumentException(SR.Format_StringZeroLength, nameof(partialName));
-
-            try
-            {
-                return Load(partialName);
-            }
-            catch (FileNotFoundException)
-            {
-                return null;
-            }
-        }
-
         // Loads the assembly with a COFF based IMAGE containing
         // an emitted assembly. The assembly is loaded into a fully isolated ALC with resolution fully deferred to the AssemblyLoadContext.Default.
         // The second parameter is the raw bytes representing the symbol store that matches the assembly.
index edc0c09..8ba1dde 100644 (file)
@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information.
 
 #nullable enable
+using System.IO;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.Loader;
@@ -22,6 +23,27 @@ namespace System.Reflection
             return RuntimeAssembly.InternalLoad(assemblyString, ref stackMark, AssemblyLoadContext.CurrentContextualReflectionContext);
         }
 
+        [Obsolete("This method has been deprecated. Please use Assembly.Load() instead. https://go.microsoft.com/fwlink/?linkid=14202")]
+        [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
+        public static Assembly? LoadWithPartialName(string partialName)
+        {
+            if (partialName == null)
+                throw new ArgumentNullException(nameof(partialName));
+
+            if ((partialName.Length == 0) || (partialName[0] == '\0'))
+                throw new ArgumentException(SR.Format_StringZeroLength, nameof(partialName));
+
+            try
+            {
+                StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+                return RuntimeAssembly.InternalLoad(partialName, ref stackMark, AssemblyLoadContext.CurrentContextualReflectionContext);
+            }
+            catch (FileNotFoundException)
+            {
+                return null;
+            }
+        }
+
         // Locate an assembly by its name. The name can be strong or
         // weak. The assembly is loaded into the domain of the caller.
         [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
index e6bc0b7..8de0ec9 100644 (file)
@@ -22,7 +22,7 @@ namespace System.Reflection
                 throw new ArgumentException(SR.Format_StringZeroLength);
 
             _name = assemblyName;
-            nInit(out RuntimeAssembly? dummy, false);
+            nInit();
         }
 
         internal AssemblyName(string? name,
@@ -49,7 +49,7 @@ namespace System.Reflection
         }
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        internal extern void nInit(out RuntimeAssembly? assembly, bool raiseResolveEvent);
+        internal extern void nInit();
         
         // This call opens and closes the file, but does not add the
         // assembly to the domain.
index a97fddc..cde1549 100644 (file)
@@ -306,38 +306,11 @@ namespace System.Reflection
 
         internal static RuntimeAssembly InternalLoad(string assemblyString, ref StackCrawlMark stackMark, AssemblyLoadContext? assemblyLoadContext = null)
         {
-            RuntimeAssembly? assembly;
-            AssemblyName an = CreateAssemblyName(assemblyString, out assembly);
-
-            if (assembly != null)
-            {
-                // The assembly was returned from ResolveAssemblyEvent
-                return assembly;
-            }
+            AssemblyName an = new AssemblyName(assemblyString);
 
             return InternalLoadAssemblyName(an, ref stackMark, assemblyLoadContext);
         }
 
-        // Creates AssemblyName. Fills assembly if AssemblyResolve event has been raised.
-        internal static AssemblyName CreateAssemblyName(
-            string assemblyString,
-            out RuntimeAssembly? assemblyFromResolveEvent)
-        {
-            if (assemblyString == null)
-                throw new ArgumentNullException(nameof(assemblyString));
-
-            if ((assemblyString.Length == 0) ||
-                (assemblyString[0] == '\0'))
-                throw new ArgumentException(SR.Format_StringZeroLength);
-
-            AssemblyName an = new AssemblyName();
-
-            an.Name = assemblyString;
-            an.nInit(out assemblyFromResolveEvent, true);
-
-            return an;
-        }
-
         internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext? assemblyLoadContext = null)
         {
 #if FEATURE_APPX
index 6c95d05..ebbc485 100644 (file)
@@ -149,7 +149,7 @@ FCIMPL1(Object*, AssemblyNameNative::GetPublicKeyToken, Object* refThisUNSAFE)
 FCIMPLEND
 
 
-FCIMPL3(void, AssemblyNameNative::Init, Object * refThisUNSAFE, OBJECTREF * pAssemblyRef, CLR_BOOL fRaiseResolveEvent)
+FCIMPL1(void, AssemblyNameNative::Init, Object * refThisUNSAFE)
 {
     FCALL_CONTRACT;
 
@@ -158,8 +158,6 @@ FCIMPL3(void, AssemblyNameNative::Init, Object * refThisUNSAFE, OBJECTREF * pAss
     
     HELPER_METHOD_FRAME_BEGIN_1(pThis);
     
-    *pAssemblyRef = NULL;
-
     if (pThis == NULL)
         COMPlusThrow(kNullReferenceException, W("NullReference_This"));
 
@@ -174,19 +172,6 @@ FCIMPL3(void, AssemblyNameNative::Init, Object * refThisUNSAFE, OBJECTREF * pAss
     {
         spec.AssemblyNameInit(&pThis,NULL);
     }
-    else if ((hr == FUSION_E_INVALID_NAME) && fRaiseResolveEvent)
-    {
-        Assembly * pAssembly = GetAppDomain()->RaiseAssemblyResolveEvent(&spec);
-
-        if (pAssembly == NULL)
-        {
-            EEFileLoadException::Throw(&spec, hr);
-        }
-        else
-        {
-            *((OBJECTREF *) (&(*pAssemblyRef))) = pAssembly->GetExposedObject();
-        }
-    }
     else
     {
         ThrowHR(hr);
index 0bfb0b5..41e2b27 100644 (file)
@@ -23,7 +23,7 @@ public:
     static FCDECL1(Object*, ToString, Object* refThisUNSAFE);
     static FCDECL1(Object*, GetPublicKeyToken, Object* refThisUNSAFE);
     static FCDECL1(Object*, EscapeCodeBase, StringObject* filenameUNSAFE);
-    static FCDECL3(void, Init, Object * refThisUNSAFE, OBJECTREF * pAssemblyRef, CLR_BOOL fRaiseResolveEvent);
+    static FCDECL1(void, Init, Object * refThisUNSAFE);
 };
 
 #endif  // _AssemblyName_H
index e8428f5..7613beb 100644 (file)
                     "name": "System.Tests.VersionTests.Comparisons_NullArgument_ThrowsArgumentNullException",
                     "reason":  "Version was improved to no longer throw from comparison operators"
                 },
+                {
+                    "name" : "System.Tests.ActivatorNetcoreTests.CreateInstanceAssemblyResolve",
+                    "reason" : "Waiting for https://github.com/dotnet/corefx/pull/37080"
+                }
             ]
         }
     },