summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSteve MacLean <stmaclea@microsoft.com>2019-04-13 19:03:56 -0400
committerGitHub <noreply@github.com>2019-04-13 19:03:56 -0400
commitf08c5c39c5bd7f594ff0b42a7167e6be9205ede7 (patch)
treed4e9ad5074832089e1ecf1a13e2197a476d0ae15 /src
parentaab61f13d31538b2a70e53435d539121e5fd4c8a (diff)
downloadcoreclr-f08c5c39c5bd7f594ff0b42a7167e6be9205ede7.tar.gz
coreclr-f08c5c39c5bd7f594ff0b42a7167e6be9205ede7.tar.bz2
coreclr-f08c5c39c5bd7f594ff0b42a7167e6be9205ede7.zip
EnterContextualReflection handle null (#23953)
* EnterContextualReflection handle null * Add ContextualReflection MockAssembly test * Fix ContextualReflection typo
Diffstat (limited to 'src')
-rw-r--r--src/System.Private.CoreLib/Resources/Strings.resx5
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs15
2 files changed, 16 insertions, 4 deletions
diff --git a/src/System.Private.CoreLib/Resources/Strings.resx b/src/System.Private.CoreLib/Resources/Strings.resx
index 9fed81d6bf..9e2c84b4d1 100644
--- a/src/System.Private.CoreLib/Resources/Strings.resx
+++ b/src/System.Private.CoreLib/Resources/Strings.resx
@@ -541,6 +541,9 @@
<data name="Arg_MustBePrimArray" xml:space="preserve">
<value>Object must be an array of primitives.</value>
</data>
+ <data name="Arg_MustBeRuntimeAssembly" xml:space="preserve">
+ <value>Object must be of type RuntimeAssembly.</value>
+ </data>
<data name="Arg_MustBeSByte" xml:space="preserve">
<value>Object must be of type SByte.</value>
</data>
@@ -3751,4 +3754,4 @@
<data name="Argument_StartupHookAssemblyLoadFailed" xml:space="preserve">
<value>Startup hook assembly '{0}' failed to load. See inner exception for details.</value>
</data>
-</root> \ No newline at end of file
+</root>
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs b/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs
index 4efd5dec1d..70d5f10cf3 100644
--- a/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs
+++ b/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs
@@ -509,9 +509,18 @@ namespace System.Runtime.Loader
/// </remarks>
public static ContextualReflectionScope EnterContextualReflection(Assembly activating)
{
- return activating != null ?
- GetLoadContext(activating).EnterContextualReflection() :
- new ContextualReflectionScope(null);
+ if (activating == null)
+ return new ContextualReflectionScope(null);
+
+ AssemblyLoadContext assemblyLoadContext = GetLoadContext(activating);
+
+ if (assemblyLoadContext == null)
+ {
+ // All RuntimeAssemblies & Only RuntimeAssemblies have an AssemblyLoadContext
+ throw new ArgumentException(SR.Arg_MustBeRuntimeAssembly, nameof(activating));
+ }
+
+ return assemblyLoadContext.EnterContextualReflection();
}
/// <summary>Opaque disposable struct used to restore CurrentContextualReflectionContext</summary>