Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a36bc61

Browse files
authored
Fix AssemblyName cache hash and key (#24138)
* 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 dotnet/corefx#37071
1 parent c489692 commit a36bc61

File tree

6 files changed

+33
-7
lines changed

6 files changed

+33
-7
lines changed

src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ internal class RuntimeAssembly : Assembly
2525
private event ModuleResolveEventHandler _ModuleResolve;
2626
private string? m_fullname;
2727
private object? m_syncRoot; // Used to keep collectible types alive and as the syncroot for reflection.emit
28+
#pragma warning disable 169
2829
private IntPtr m_assembly; // slack for ptr datum on unmanaged side
30+
#pragma warning restore 169
2931

3032
#endregion
3133

src/binder/assemblyname.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,15 @@ namespace BINDER_SPACE
486486
{
487487
dwUseIdentityFlags &= ~AssemblyIdentity::IDENTITY_FLAG_CONTENT_TYPE;
488488
}
489+
if ((dwIncludeFlags & INCLUDE_PUBLIC_KEY_TOKEN) == 0)
490+
{
491+
dwUseIdentityFlags &= ~AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY;
492+
dwUseIdentityFlags &= ~AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN;
493+
}
494+
if ((dwIncludeFlags & EXCLUDE_CULTURE) != 0)
495+
{
496+
dwUseIdentityFlags &= ~AssemblyIdentity::IDENTITY_FLAG_CULTURE;
497+
}
489498

490499
dwHash ^= static_cast<DWORD>(HashCaseInsensitive(GetSimpleName()));
491500
dwHash = _rotl(dwHash, 4);

src/vm/assemblynative.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ FCIMPL6(Object*, AssemblyNative::Load, AssemblyNameBaseObject* assemblyNameUNSAF
7878
else
7979
{
8080
// Compute parent assembly
81-
if (gc.requestingAssembly == NULL)
81+
if (gc.requestingAssembly != NULL)
8282
{
83-
pRefAssembly = SystemDomain::GetCallersAssembly(stackMark);
83+
pRefAssembly = gc.requestingAssembly->GetAssembly();
8484
}
85-
else
85+
else if (ptrLoadContextBinder == NULL)
8686
{
87-
pRefAssembly = gc.requestingAssembly->GetAssembly();
87+
pRefAssembly = SystemDomain::GetCallersAssembly(stackMark);
8888
}
8989

9090
if (pRefAssembly)
9191
{
92-
pParentAssembly= pRefAssembly->GetDomainAssembly();
92+
pParentAssembly = pRefAssembly->GetDomainAssembly();
9393
}
9494
}
9595

tests/CoreFX/CoreFX.issues.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,20 @@
11491149
]
11501150
}
11511151
},
1152+
{
1153+
"name": "System.Runtime.Loader.DefaultContext.Tests",
1154+
"enabled": true,
1155+
"exclusions": {
1156+
"namespaces": null,
1157+
"classes": null,
1158+
"methods": [
1159+
{
1160+
"name" : "System.Runtime.Loader.Tests.DefaultLoadContextTests.LoadInDefaultContext",
1161+
"reason" : "Waiting for https://github.com/dotnet/corefx/pull/37071"
1162+
}
1163+
]
1164+
}
1165+
},
11521166
{
11531167
"name": "System.Runtime.Loader.Tests",
11541168
"enabled": true,

tests/src/Loader/ContextualReflection/ContextualReflection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ void TestAssemblyLoad(bool isolated)
321321
{
322322
TestAssemblyLoad(isolated, (string assemblyName) => Assembly.Load(assemblyName));
323323
TestAssemblyLoad(isolated, (string assemblyName) => Assembly.Load(new AssemblyName(assemblyName)));
324+
#pragma warning disable 618
325+
TestAssemblyLoad(isolated, (string assemblyName) => Assembly.LoadWithPartialName(assemblyName));
326+
#pragma warning restore 618
324327
}
325328

326329
void TestAssemblyLoad(bool isolated, Func<string, Assembly> assemblyLoad)
@@ -748,7 +751,6 @@ public void RunTests(bool isolated)
748751
TestMockAssemblyThrows();
749752
}
750753

751-
[MethodImplAttribute(MethodImplOptions.NoInlining)]
752754
public void RunTestsIsolated()
753755
{
754756
VerifyIsolationAlc();

tests/src/Loader/ContextualReflection/ContextualReflectionDependency.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public interface IProgram
1616
Assembly alcAssembly { get; }
1717
Type alcProgramType { get; }
1818
IProgram alcProgramInstance { get; }
19-
[MethodImplAttribute(MethodImplOptions.NoInlining)]
2019
void RunTestsIsolated();
2120
}
2221

0 commit comments

Comments
 (0)