Fix AssemblyName cache hash and key (#24138)
authorSteve MacLean <stmaclea@microsoft.com>
Sun, 21 Apr 2019 22:25:04 +0000 (18:25 -0400)
committerGitHub <noreply@github.com>
Sun, 21 Apr 2019 22:25:04 +0000 (18:25 -0400)
* Add ContextualReflection LoadWithPartialName case

* Remove unnecessary MethodImplOptions.NoInlining

* Remove m_assembly warning

* Fix AssemblyName hash function

* AssemblyNative::Load fix stackMark usage

Do not use the stackMark if (ptrLoadContextBinder != NULL)

* Temporarily disable DefaultContextOverrideTPA

Test is failing due to a logic error.
Fix is pending in https://github.com/dotnet/corefx/pull/37071

src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
src/binder/assemblyname.cpp
src/vm/assemblynative.cpp
tests/CoreFX/CoreFX.issues.json
tests/src/Loader/ContextualReflection/ContextualReflection.cs
tests/src/Loader/ContextualReflection/ContextualReflectionDependency.cs

index 16dc8ec..a97fddc 100644 (file)
@@ -25,7 +25,9 @@ namespace System.Reflection
         private event ModuleResolveEventHandler _ModuleResolve;
         private string? m_fullname;
         private object? m_syncRoot;   // Used to keep collectible types alive and as the syncroot for reflection.emit
+#pragma warning disable 169
         private IntPtr m_assembly;    // slack for ptr datum on unmanaged side
+#pragma warning restore 169
 
         #endregion
 
index 616869b..bc97814 100644 (file)
@@ -486,6 +486,15 @@ Exit:
         {
             dwUseIdentityFlags &= ~AssemblyIdentity::IDENTITY_FLAG_CONTENT_TYPE;
         }
+        if ((dwIncludeFlags & INCLUDE_PUBLIC_KEY_TOKEN) == 0)
+        {
+            dwUseIdentityFlags &= ~AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY;
+            dwUseIdentityFlags &= ~AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN;
+        }
+        if ((dwIncludeFlags & EXCLUDE_CULTURE) != 0)
+        {
+            dwUseIdentityFlags &= ~AssemblyIdentity::IDENTITY_FLAG_CULTURE;
+        }
 
         dwHash ^= static_cast<DWORD>(HashCaseInsensitive(GetSimpleName()));
         dwHash = _rotl(dwHash, 4);
index aa83093..cc95151 100644 (file)
@@ -78,18 +78,18 @@ FCIMPL6(Object*, AssemblyNative::Load, AssemblyNameBaseObject* assemblyNameUNSAF
     else
     {
         // Compute parent assembly
-        if (gc.requestingAssembly == NULL)
+        if (gc.requestingAssembly != NULL)
         {
-            pRefAssembly = SystemDomain::GetCallersAssembly(stackMark);
+            pRefAssembly = gc.requestingAssembly->GetAssembly();
         }
-        else
+        else if (ptrLoadContextBinder == NULL)
         {
-            pRefAssembly = gc.requestingAssembly->GetAssembly();
+            pRefAssembly = SystemDomain::GetCallersAssembly(stackMark);
         }
         
         if (pRefAssembly)
         {
-            pParentAssembly= pRefAssembly->GetDomainAssembly();
+            pParentAssembly = pRefAssembly->GetDomainAssembly();
         }
     }
 
index b0eb61c..e8428f5 100644 (file)
         }
     },
     {
+        "name": "System.Runtime.Loader.DefaultContext.Tests",
+        "enabled": true,
+        "exclusions": {
+            "namespaces": null,
+            "classes": null,
+            "methods": [
+                {
+                    "name" : "System.Runtime.Loader.Tests.DefaultLoadContextTests.LoadInDefaultContext",
+                    "reason" : "Waiting for https://github.com/dotnet/corefx/pull/37071"
+                }
+            ]
+        }
+    },
+    {
         "name": "System.Runtime.Loader.Tests",
         "enabled": true,
         "exclusions": {
index 1612c14..2c1d081 100644 (file)
@@ -321,6 +321,9 @@ namespace ContextualReflectionTest
         {
             TestAssemblyLoad(isolated, (string assemblyName) => Assembly.Load(assemblyName));
             TestAssemblyLoad(isolated, (string assemblyName) => Assembly.Load(new AssemblyName(assemblyName)));
+#pragma warning disable 618
+            TestAssemblyLoad(isolated, (string assemblyName) => Assembly.LoadWithPartialName(assemblyName));
+#pragma warning restore 618
         }
 
         void TestAssemblyLoad(bool isolated, Func<string, Assembly> assemblyLoad)
@@ -748,7 +751,6 @@ namespace ContextualReflectionTest
             TestMockAssemblyThrows();
         }
 
-        [MethodImplAttribute(MethodImplOptions.NoInlining)]
         public void RunTestsIsolated()
         {
             VerifyIsolationAlc();
index f498db4..933194a 100644 (file)
@@ -16,7 +16,6 @@ namespace ContextualReflectionTest
         Assembly alcAssembly { get; }
         Type alcProgramType { get; }
         IProgram alcProgramInstance { get; }
-        [MethodImplAttribute(MethodImplOptions.NoInlining)]
         void RunTestsIsolated();
     }