Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide ALC name in DispatchProxy for proxies in custom ALC #92385

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/coreclr/vm/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,7 @@ 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)
if (COMCharacter::nativeIsWhiteSpace(pAssemblyNameParts->_pName[0]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this check as well?

{
COMPlusThrow(kArgumentException, W("InvalidAssemblyName"));
}
Expand Down Expand Up @@ -1132,7 +1129,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
2 changes: 0 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))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests should be replaced by positive tests

[InlineData(" ", typeof(FileLoadException))]
[InlineData(" \t \r \n ", typeof(FileLoadException))]
[InlineData("aa, culture=en-en, culture=en-en", typeof(FileLoadException))]
Expand All @@ -111,7 +110,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