Skip to content

Commit

Permalink
Provide ALC name in DispatchProxy for proxies in custom ALC (#92385)
Browse files Browse the repository at this point in the history
Fixes #82969
  • Loading branch information
pedrobsaila authored Sep 22, 2023
1 parent e0a4bdd commit b842334
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
10 changes: 1 addition & 9 deletions src/coreclr/vm/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,6 @@ Assembly *Assembly::CreateDynamic(AssemblyBinder* pBinder, NativeAssemblyNamePar
if (pAssemblyNameParts->_pName == NULL || pAssemblyNameParts->_pName[0] == '\0')
COMPlusThrow(kArgumentException, W("ArgumentNull_AssemblyNameName"));

if (COMCharacter::nativeIsWhiteSpace(pAssemblyNameParts->_pName[0])
|| u16_strchr(pAssemblyNameParts->_pName, '\\') != NULL
|| u16_strchr(pAssemblyNameParts->_pName, ':') != NULL
|| u16_strchr(pAssemblyNameParts->_pName, '/') != NULL)
{
COMPlusThrow(kArgumentException, W("InvalidAssemblyName"));
}

// Set up the assembly manifest metadata
// When we create dynamic assembly, we always use a working copy of IMetaDataAssemblyEmit
// to store temporary runtime assembly information. This is to preserve the invariant that
Expand Down Expand Up @@ -1132,7 +1124,7 @@ void Assembly::AddDiagnosticStartupHookPath(LPCWSTR wszPath)
size_t cchDiagnosticStartupHookPathsLocal = 0;
if (nullptr != wszDiagnosticStartupHookPathsLocal)
{
cchDiagnosticStartupHookPathsLocal = u16_strlen(wszDiagnosticStartupHookPathsLocal);
cchDiagnosticStartupHookPathsLocal = u16_strlen(wszDiagnosticStartupHookPathsLocal);
// Add 1 for the path separator
cchDiagnosticStartupHookPathsNew += cchDiagnosticStartupHookPathsLocal + 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private AssemblyNameParts Parse()
if (token != Token.String)
ThrowInvalidAssemblyName();

if (string.IsNullOrEmpty(name) || name.AsSpan().ContainsAny('/', '\\', ':'))
if (string.IsNullOrEmpty(name))
ThrowInvalidAssemblyName();

Version? version = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,20 @@ private sealed class ProxyAssembly
[RequiresDynamicCode("Defining a dynamic assembly requires generating code at runtime")]
public ProxyAssembly(AssemblyLoadContext alc)
{
string name;
if (alc == AssemblyLoadContext.Default)
{
name = "ProxyBuilder";
}
else
{
string? alcName = alc.Name;
name = string.IsNullOrEmpty(alcName) ? $"DispatchProxyTypes.{alc.GetHashCode()}" : $"DispatchProxyTypes.{new AssemblyName { Name = alcName }}";
}

AssemblyBuilderAccess builderAccess =
alc.IsCollectible ? AssemblyBuilderAccess.RunAndCollect : AssemblyBuilderAccess.Run;
_ab = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("ProxyBuilder"), builderAccess);
_ab = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(name), builderAccess);
_mb = _ab.DefineDynamicModule("testmod");
}

Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Reflection/tests/AssemblyNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public void Ctor_String_Public_Key(string name, string expectedName)
[InlineData("", typeof(ArgumentException))]
[InlineData("\0", typeof(ArgumentException))]
[InlineData("\0a", typeof(ArgumentException))]
[InlineData("/a", typeof(FileLoadException))]
[InlineData(" ", typeof(FileLoadException))]
[InlineData(" \t \r \n ", typeof(FileLoadException))]
[InlineData("aa, culture=en-en, culture=en-en", typeof(FileLoadException))]
Expand All @@ -103,6 +102,8 @@ public void Ctor_String_Invalid(string assemblyName, Type exceptionType)
[InlineData("aaaa, custom=10", "aaaa")]
[InlineData("aaaa, custom=10, custom=20", "aaaa")]
[InlineData("aaaa, custom=lalala", "aaaa")]
[InlineData("/a", "/a")]
[InlineData("aa/name ", "aa/name")]
public void Ctor_String_Valid_Legacy(string name, string expectedName)
{
AssemblyName assemblyName = new AssemblyName(name);
Expand All @@ -111,7 +112,6 @@ public void Ctor_String_Valid_Legacy(string name, string expectedName)

[Theory]
[InlineData("name\\u50; ", typeof(FileLoadException))]
[InlineData("aa/name ", typeof(FileLoadException))]
[InlineData("aa\\/tname", typeof(FileLoadException))]
[InlineData("aaaa, publickey=neutral", typeof(FileLoadException))]
[InlineData("aaaa, publickeytoken=neutral", typeof(FileLoadException))]
Expand Down

0 comments on commit b842334

Please sign in to comment.