diff options
author | Steve MacLean <stmaclea@microsoft.com> | 2019-04-14 02:03:56 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2019-04-14 16:54:18 +0300 |
commit | 64c073321296b86f087d66ba45cf3d49dfb9e208 (patch) | |
tree | bbd26d82bac2dbabc7ca10d5e49e7e46ad653e71 /netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs | |
parent | a49d96b057967b09d910adbd592418a1cab245a8 (diff) |
EnterContextualReflection handle null (dotnet/coreclr#23953)
* EnterContextualReflection handle null
* Add ContextualReflection MockAssembly test
* Fix ContextualReflection typo
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Diffstat (limited to 'netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs')
-rw-r--r-- | netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs index 4efd5dec1d5..70d5f10cf3d 100644 --- a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/netcore/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> |