Skip to content

Commit

Permalink
Merge in 'release/7.0' changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dotnet-bot committed Mar 10, 2023
2 parents 15f5d02 + 01a25fa commit 0f05efe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,9 @@ 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.{alcName}";
}
AssemblyBuilderAccess builderAccess =
alc.IsCollectible ? AssemblyBuilderAccess.RunAndCollect : AssemblyBuilderAccess.Run;
_ab = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(name), builderAccess);
_ab = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("ProxyBuilder"), builderAccess);
_mb = _ab.DefineDynamicModule("testmod");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,5 +681,24 @@ static object CreateTestDispatchProxy(Type type) =>
.MakeGenericMethod(typeof(IDisposable), type)
.Invoke(null, null);
}

[Fact]
public static void Test_Multiple_AssemblyLoadContextsWithBadName()
{
if (typeof(DispatchProxyTests).Assembly.Location == "")
return;

Assembly assembly = Assembly.LoadFile(typeof(DispatchProxyTests).Assembly.Location);
Type type = assembly.GetType(typeof(DispatchProxyTests).FullName);
MethodInfo method = type.GetMethod(nameof(Demo), BindingFlags.NonPublic | BindingFlags.Static);
Assert.True((bool)method.Invoke(null, null));
}

internal static bool Demo()
{
TestType_IHelloService proxy = DispatchProxy.Create<TestType_IHelloService, InternalInvokeProxy>();
proxy.Hello("Hello");
return true;
}
}
}

0 comments on commit 0f05efe

Please sign in to comment.