diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index 7da608d5e17a5..8833aa45742b3 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -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 @@ -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; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameParser.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameParser.cs index 2b8a93ff4f268..dbaaefd4d8c9d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameParser.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameParser.cs @@ -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; diff --git a/src/libraries/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxyGenerator.cs b/src/libraries/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxyGenerator.cs index 891daac1b52be..d6ba3df9a9f81 100644 --- a/src/libraries/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxyGenerator.cs +++ b/src/libraries/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxyGenerator.cs @@ -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"); } diff --git a/src/libraries/System.Reflection/tests/AssemblyNameTests.cs b/src/libraries/System.Reflection/tests/AssemblyNameTests.cs index 1960027c1ff13..a2bf600407298 100644 --- a/src/libraries/System.Reflection/tests/AssemblyNameTests.cs +++ b/src/libraries/System.Reflection/tests/AssemblyNameTests.cs @@ -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))] @@ -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); @@ -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))]