Skip to content

Commit b842334

Browse files
authored
Provide ALC name in DispatchProxy for proxies in custom ALC (#92385)
Fixes #82969
1 parent e0a4bdd commit b842334

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

src/coreclr/vm/assembly.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,6 @@ Assembly *Assembly::CreateDynamic(AssemblyBinder* pBinder, NativeAssemblyNamePar
397397
if (pAssemblyNameParts->_pName == NULL || pAssemblyNameParts->_pName[0] == '\0')
398398
COMPlusThrow(kArgumentException, W("ArgumentNull_AssemblyNameName"));
399399

400-
if (COMCharacter::nativeIsWhiteSpace(pAssemblyNameParts->_pName[0])
401-
|| u16_strchr(pAssemblyNameParts->_pName, '\\') != NULL
402-
|| u16_strchr(pAssemblyNameParts->_pName, ':') != NULL
403-
|| u16_strchr(pAssemblyNameParts->_pName, '/') != NULL)
404-
{
405-
COMPlusThrow(kArgumentException, W("InvalidAssemblyName"));
406-
}
407-
408400
// Set up the assembly manifest metadata
409401
// When we create dynamic assembly, we always use a working copy of IMetaDataAssemblyEmit
410402
// to store temporary runtime assembly information. This is to preserve the invariant that
@@ -1132,7 +1124,7 @@ void Assembly::AddDiagnosticStartupHookPath(LPCWSTR wszPath)
11321124
size_t cchDiagnosticStartupHookPathsLocal = 0;
11331125
if (nullptr != wszDiagnosticStartupHookPathsLocal)
11341126
{
1135-
cchDiagnosticStartupHookPathsLocal = u16_strlen(wszDiagnosticStartupHookPathsLocal);
1127+
cchDiagnosticStartupHookPathsLocal = u16_strlen(wszDiagnosticStartupHookPathsLocal);
11361128
// Add 1 for the path separator
11371129
cchDiagnosticStartupHookPathsNew += cchDiagnosticStartupHookPathsLocal + 1;
11381130
}

src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameParser.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private AssemblyNameParts Parse()
9090
if (token != Token.String)
9191
ThrowInvalidAssemblyName();
9292

93-
if (string.IsNullOrEmpty(name) || name.AsSpan().ContainsAny('/', '\\', ':'))
93+
if (string.IsNullOrEmpty(name))
9494
ThrowInvalidAssemblyName();
9595

9696
Version? version = null;

src/libraries/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxyGenerator.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,20 @@ private sealed class ProxyAssembly
118118
[RequiresDynamicCode("Defining a dynamic assembly requires generating code at runtime")]
119119
public ProxyAssembly(AssemblyLoadContext alc)
120120
{
121+
string name;
122+
if (alc == AssemblyLoadContext.Default)
123+
{
124+
name = "ProxyBuilder";
125+
}
126+
else
127+
{
128+
string? alcName = alc.Name;
129+
name = string.IsNullOrEmpty(alcName) ? $"DispatchProxyTypes.{alc.GetHashCode()}" : $"DispatchProxyTypes.{new AssemblyName { Name = alcName }}";
130+
}
131+
121132
AssemblyBuilderAccess builderAccess =
122133
alc.IsCollectible ? AssemblyBuilderAccess.RunAndCollect : AssemblyBuilderAccess.Run;
123-
_ab = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("ProxyBuilder"), builderAccess);
134+
_ab = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(name), builderAccess);
124135
_mb = _ab.DefineDynamicModule("testmod");
125136
}
126137

src/libraries/System.Reflection/tests/AssemblyNameTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public void Ctor_String_Public_Key(string name, string expectedName)
8686
[InlineData("", typeof(ArgumentException))]
8787
[InlineData("\0", typeof(ArgumentException))]
8888
[InlineData("\0a", typeof(ArgumentException))]
89-
[InlineData("/a", typeof(FileLoadException))]
9089
[InlineData(" ", typeof(FileLoadException))]
9190
[InlineData(" \t \r \n ", typeof(FileLoadException))]
9291
[InlineData("aa, culture=en-en, culture=en-en", typeof(FileLoadException))]
@@ -103,6 +102,8 @@ public void Ctor_String_Invalid(string assemblyName, Type exceptionType)
103102
[InlineData("aaaa, custom=10", "aaaa")]
104103
[InlineData("aaaa, custom=10, custom=20", "aaaa")]
105104
[InlineData("aaaa, custom=lalala", "aaaa")]
105+
[InlineData("/a", "/a")]
106+
[InlineData("aa/name ", "aa/name")]
106107
public void Ctor_String_Valid_Legacy(string name, string expectedName)
107108
{
108109
AssemblyName assemblyName = new AssemblyName(name);
@@ -111,7 +112,6 @@ public void Ctor_String_Valid_Legacy(string name, string expectedName)
111112

112113
[Theory]
113114
[InlineData("name\\u50; ", typeof(FileLoadException))]
114-
[InlineData("aa/name ", typeof(FileLoadException))]
115115
[InlineData("aa\\/tname", typeof(FileLoadException))]
116116
[InlineData("aaaa, publickey=neutral", typeof(FileLoadException))]
117117
[InlineData("aaaa, publickeytoken=neutral", typeof(FileLoadException))]

0 commit comments

Comments
 (0)