From d86ae9fe602a7d0970fc001a1eed49f767bd36d8 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Mon, 17 Apr 2017 11:47:47 -0700 Subject: [PATCH] In function Assembly.Load ignore AssemblyName.CodeBase even if it is set (dotnet/coreclr#11010) Commit migrated from https://github.com/dotnet/coreclr/commit/e82d10df9dd3de87d575ab488f320287f2d5f61b --- src/coreclr/src/mscorlib/Resources/Strings.resx | 3 --- .../src/System/Reflection/Assembly.CoreCLR.cs | 24 ++++++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/coreclr/src/mscorlib/Resources/Strings.resx b/src/coreclr/src/mscorlib/Resources/Strings.resx index cb9474f..84c1cfc 100644 --- a/src/coreclr/src/mscorlib/Resources/Strings.resx +++ b/src/coreclr/src/mscorlib/Resources/Strings.resx @@ -2864,9 +2864,6 @@ {0} is not supported in AppX. - - Assembly.Load with a Codebase is not supported. - Assembly.LoadFrom with hashValue is not supported. diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/Assembly.CoreCLR.cs b/src/coreclr/src/mscorlib/src/System/Reflection/Assembly.CoreCLR.cs index 82966db..708f79b 100644 --- a/src/coreclr/src/mscorlib/src/System/Reflection/Assembly.CoreCLR.cs +++ b/src/coreclr/src/mscorlib/src/System/Reflection/Assembly.CoreCLR.cs @@ -101,14 +101,20 @@ namespace System.Reflection { Contract.Ensures(Contract.Result() != null); Contract.Ensures(!Contract.Result().ReflectionOnly); - + + AssemblyName modifiedAssemblyRef = null; if (assemblyRef != null && assemblyRef.CodeBase != null) { - throw new NotSupportedException(SR.NotSupported_AssemblyLoadCodeBase); + modifiedAssemblyRef = (AssemblyName)assemblyRef.Clone(); + modifiedAssemblyRef.CodeBase = null; } - + else + { + modifiedAssemblyRef = assemblyRef; + } + StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return RuntimeAssembly.InternalLoadAssemblyName(assemblyRef, null, null, ref stackMark, true /*thrownOnFileNotFound*/, false /*forIntrospection*/); + return RuntimeAssembly.InternalLoadAssemblyName(modifiedAssemblyRef, null, null, ref stackMark, true /*thrownOnFileNotFound*/, false /*forIntrospection*/); } // Locate an assembly by its name. The name can be strong or @@ -119,13 +125,19 @@ namespace System.Reflection Contract.Ensures(Contract.Result() != null); Contract.Ensures(!Contract.Result().ReflectionOnly); + AssemblyName modifiedAssemblyRef = null; if (assemblyRef != null && assemblyRef.CodeBase != null) { - throw new NotSupportedException(SR.NotSupported_AssemblyLoadCodeBase); + modifiedAssemblyRef = (AssemblyName)assemblyRef.Clone(); + modifiedAssemblyRef.CodeBase = null; + } + else + { + modifiedAssemblyRef = assemblyRef; } StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return RuntimeAssembly.InternalLoadAssemblyName(assemblyRef, null, null, ref stackMark, true /*thrownOnFileNotFound*/, false /*forIntrospection*/, ptrLoadContextBinder); + return RuntimeAssembly.InternalLoadAssemblyName(modifiedAssemblyRef, null, null, ref stackMark, true /*thrownOnFileNotFound*/, false /*forIntrospection*/, ptrLoadContextBinder); } // Loads the assembly with a COFF based IMAGE containing -- 2.7.4