Skip to content

Commit 5a834d4

Browse files
authored
[jnimarshalmethod-gen] Avoid creating AppDomains (#720)
This is part of getting `jnimarshalmethod-gen` to work on Windows and later with .NET 5. The created `AppDomain` was used to isolate processed assembly, so that we could unload it and rewrite with generated changes; see 2a9ac6a. That didn't work on Windows even with .NET Framework, which has the full `AppDomain` API. In .NET 5, `AppDomain`s can't be created. Instead of using `AppDomain`s, pre-load the assembly in memory and load it from there. This avoids the file sharing issues.
1 parent a76edb8 commit 5a834d4

File tree

1 file changed

+2
-7
lines changed
  • tools/jnimarshalmethod-gen

1 file changed

+2
-7
lines changed

tools/jnimarshalmethod-gen/App.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,13 @@ class App : MarshalByRefObject
3939

4040
public static int Main (string [] args)
4141
{
42-
var domain = AppDomain.CreateDomain ("workspace");
43-
var app = (App)domain.CreateInstanceAndUnwrap (typeof (App).Assembly.FullName, typeof (App).FullName);
44-
42+
var app = new App ();
4543
app.AddMonoPathToResolverSearchDirectories ();
4644

4745
var assemblies = app.ProcessArguments (args);
4846
app.ProcessAssemblies (assemblies);
4947
var filesToDelete = app.FilesToDelete;
5048

51-
AppDomain.Unload (domain);
52-
5349
foreach (var path in filesToDelete)
5450
File.Delete (path);
5551

@@ -282,8 +278,7 @@ public int Compare (MethodInfo a, MethodInfo b)
282278

283279
void CreateMarshalMethodAssembly (string path)
284280
{
285-
var assembly = Assembly.LoadFile (Path.GetFullPath (path));
286-
281+
var assembly = Assembly.Load (File.ReadAllBytes (Path.GetFullPath (path)));
287282
var baseName = Path.GetFileNameWithoutExtension (path);
288283
var assemblyName = new AssemblyName (baseName + "-JniMarshalMethods");
289284
var fileName = assemblyName.Name + ".dll";

0 commit comments

Comments
 (0)