File tree Expand file tree Collapse file tree 2 files changed +20
-11
lines changed
src/libraries/System.Reflection.DispatchProxy Expand file tree Collapse file tree 2 files changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -117,19 +117,9 @@ private sealed class ProxyAssembly
117117 [ RequiresDynamicCode ( "Defining a dynamic assembly requires generating code at runtime" ) ]
118118 public ProxyAssembly ( AssemblyLoadContext alc )
119119 {
120- string name ;
121- if ( alc == AssemblyLoadContext . Default )
122- {
123- name = "ProxyBuilder" ;
124- }
125- else
126- {
127- string ? alcName = alc . Name ;
128- name = string . IsNullOrEmpty ( alcName ) ? $ "DispatchProxyTypes.{ alc . GetHashCode ( ) } " : $ "DispatchProxyTypes.{ alcName } ";
129- }
130120 AssemblyBuilderAccess builderAccess =
131121 alc . IsCollectible ? AssemblyBuilderAccess . RunAndCollect : AssemblyBuilderAccess . Run ;
132- _ab = AssemblyBuilder . DefineDynamicAssembly ( new AssemblyName ( name ) , builderAccess ) ;
122+ _ab = AssemblyBuilder . DefineDynamicAssembly ( new AssemblyName ( "ProxyBuilder" ) , builderAccess ) ;
133123 _mb = _ab . DefineDynamicModule ( "testmod" ) ;
134124 }
135125
Original file line number Diff line number Diff line change @@ -681,5 +681,24 @@ static object CreateTestDispatchProxy(Type type) =>
681681 . MakeGenericMethod ( typeof ( IDisposable ) , type )
682682 . Invoke ( null , null ) ;
683683 }
684+
685+ [ Fact ]
686+ public static void Test_Multiple_AssemblyLoadContextsWithBadName ( )
687+ {
688+ if ( typeof ( DispatchProxyTests ) . Assembly . Location == "" )
689+ return ;
690+
691+ Assembly assembly = Assembly . LoadFile ( typeof ( DispatchProxyTests ) . Assembly . Location ) ;
692+ Type type = assembly . GetType ( typeof ( DispatchProxyTests ) . FullName ) ;
693+ MethodInfo method = type . GetMethod ( nameof ( Demo ) , BindingFlags . NonPublic | BindingFlags . Static ) ;
694+ Assert . True ( ( bool ) method . Invoke ( null , null ) ) ;
695+ }
696+
697+ internal static bool Demo ( )
698+ {
699+ TestType_IHelloService proxy = DispatchProxy . Create < TestType_IHelloService , InternalInvokeProxy > ( ) ;
700+ proxy . Hello ( "Hello" ) ;
701+ return true ;
702+ }
684703 }
685704}
You can’t perform that action at this time.
0 commit comments