@@ -27,7 +27,7 @@ public void LoadLibrary()
2727 {
2828 string [ ] args = {
2929 "ijwhost" ,
30- sharedState . IjwLibraryPath ,
30+ sharedState . IjwApp . AppDll ,
3131 "NativeEntryPoint"
3232 } ;
3333 CommandResult result = sharedState . CreateNativeHostCommand ( args , sharedState . RepoDirectories . BuiltDotnet )
@@ -38,14 +38,49 @@ public void LoadLibrary()
3838 . And . HaveStdOutContaining ( "[C++/CLI] ManagedClass: AssemblyLoadContext = \" Default\" System.Runtime.Loader.DefaultAssemblyLoadContext" ) ;
3939 }
4040
41+ [ Theory ]
42+ [ InlineData ( true ) ]
43+ [ InlineData ( false ) ]
44+ public void LoadLibrary_ContextConfig ( bool load_isolated )
45+ {
46+ // make a copy of a portion of the shared state because we will modify it
47+ using ( var app = sharedState . IjwApp . Copy ( ) )
48+ {
49+ string [ ] args = {
50+ "ijwhost" ,
51+ app . AppDll ,
52+ "NativeEntryPoint"
53+ } ;
54+
55+ RuntimeConfig . FromFile ( app . RuntimeConfigJson )
56+ . WithProperty ( "System.Runtime.InteropServices.CppCLI.LoadComponentInIsolatedContext" , load_isolated . ToString ( ) )
57+ . Save ( ) ;
58+
59+ CommandResult result = sharedState . CreateNativeHostCommand ( args , sharedState . RepoDirectories . BuiltDotnet )
60+ . Execute ( ) ;
61+
62+ result . Should ( ) . Pass ( )
63+ . And . HaveStdOutContaining ( "[C++/CLI] NativeEntryPoint: calling managed class" ) ;
64+
65+ if ( load_isolated ) // Assembly should be loaded in an isolated context
66+ {
67+ result . Should ( ) . HaveStdOutContaining ( "[C++/CLI] ManagedClass: AssemblyLoadContext = \" IsolatedComponentLoadContext" ) ;
68+ }
69+ else // Assembly should be loaded in the default context
70+ {
71+ result . Should ( ) . HaveStdOutContaining ( "[C++/CLI] ManagedClass: AssemblyLoadContext = \" Default\" System.Runtime.Loader.DefaultAssemblyLoadContext" ) ;
72+ }
73+ }
74+ }
75+
4176 [ Theory ]
4277 [ InlineData ( true ) ]
4378 [ InlineData ( false ) ]
4479 public void ManagedHost ( bool selfContained )
4580 {
4681 string [ ] args = {
4782 "ijwhost" ,
48- sharedState . IjwLibraryPath ,
83+ sharedState . IjwApp . AppDll ,
4984 "NativeEntryPoint"
5085 } ;
5186 TestProjectFixture fixture = selfContained ? sharedState . ManagedHostFixture_SelfContained : sharedState . ManagedHostFixture_FrameworkDependent ;
@@ -63,24 +98,23 @@ public void ManagedHost(bool selfContained)
6398
6499 public class SharedTestState : SharedTestStateBase
65100 {
66- public string IjwLibraryPath { get ; }
101+ public TestApp IjwApp { get ; }
67102
68103 public TestProjectFixture ManagedHostFixture_FrameworkDependent { get ; }
69104 public TestProjectFixture ManagedHostFixture_SelfContained { get ; }
70105
71106 public SharedTestState ( )
72107 {
73108 string folder = Path . Combine ( BaseDirectory , "ijw" ) ;
74- Directory . CreateDirectory ( folder ) ;
109+ IjwApp = new TestApp ( folder , "ijw" ) ;
75110
76111 // Copy over ijwhost
77112 string ijwhostName = "ijwhost.dll" ;
78113 File . Copy ( Path . Combine ( RepoDirectories . HostArtifacts , ijwhostName ) , Path . Combine ( folder , ijwhostName ) ) ;
79114
80115 // Copy over the C++/CLI test library
81116 string ijwLibraryName = "ijw.dll" ;
82- IjwLibraryPath = Path . Combine ( folder , ijwLibraryName ) ;
83- File . Copy ( Path . Combine ( RepoDirectories . HostTestArtifacts , ijwLibraryName ) , IjwLibraryPath ) ;
117+ File . Copy ( Path . Combine ( RepoDirectories . HostTestArtifacts , ijwLibraryName ) , Path . Combine ( folder , ijwLibraryName ) ) ;
84118
85119 // Create a runtimeconfig.json for the C++/CLI test library
86120 new RuntimeConfig ( Path . Combine ( folder , "ijw.runtimeconfig.json" ) )
0 commit comments