Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.

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

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

  • tools/jnimarshalmethod-gen

‎tools/jnimarshalmethod-gen/App.cs‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,13 @@ class App : MarshalByRefObject
3939

4040
publicstaticintMain(string[]args)
4141
{
42-
vardomain=AppDomain.CreateDomain("workspace");
43-
varapp=(App)domain.CreateInstanceAndUnwrap(typeof(App).Assembly.FullName,typeof(App).FullName);
44-
42+
varapp=newApp();
4543
app.AddMonoPathToResolverSearchDirectories();
4644

4745
varassemblies=app.ProcessArguments(args);
4846
app.ProcessAssemblies(assemblies);
4947
varfilesToDelete=app.FilesToDelete;
5048

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

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

283279
voidCreateMarshalMethodAssembly(stringpath)
284280
{
285-
varassembly=Assembly.LoadFile(Path.GetFullPath(path));
286-
281+
varassembly=Assembly.Load(File.ReadAllBytes(Path.GetFullPath(path)));
287282
varbaseName=Path.GetFileNameWithoutExtension(path);
288283
varassemblyName=newAssemblyName(baseName+"-JniMarshalMethods");
289284
varfileName=assemblyName.Name+".dll";

0 commit comments

Comments
 (0)