Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Make scan domain work in LoadFrom context
Browse files Browse the repository at this point in the history
  • Loading branch information
mhutch committed Nov 19, 2014
1 parent ecb7dd9 commit 1efa795
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions Mono.Addins/Mono.Addins.Database/SetupDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,23 @@ public void GetAddinDescription (IProgressStatus monitor, AddinRegistry registry
ReleaseDomain ();
}
}


// ensure types from this assembly returned to this domain from the remote domain can
// be resolved even if we're in the LoadFrom context
static System.Reflection.Assembly MonoAddinsAssemblyResolve(object sender, ResolveEventArgs args)
{
var asm = typeof(SetupDomain).Assembly;
return args.Name == asm.FullName? asm : null;
}

RemoteSetupDomain GetDomain ()
{
lock (this) {
if (useCount++ == 0) {
AppDomain.CurrentDomain.AssemblyResolve += MonoAddinsAssemblyResolve;
domain = AppDomain.CreateDomain ("SetupDomain", null, AppDomain.CurrentDomain.SetupInformation);
remoteSetupDomain = (RemoteSetupDomain) domain.CreateInstanceFromAndUnwrap (typeof(RemoteSetupDomain).Assembly.Location, typeof(RemoteSetupDomain).FullName);
var type = typeof(RemoteSetupDomain);
remoteSetupDomain = (RemoteSetupDomain) domain.CreateInstanceFromAndUnwrap (type.Assembly.Location, type.FullName);
}
return remoteSetupDomain;
}
Expand All @@ -81,13 +91,24 @@ void ReleaseDomain ()
AppDomain.Unload (domain);
domain = null;
remoteSetupDomain = null;
AppDomain.CurrentDomain.AssemblyResolve -= MonoAddinsAssemblyResolve;
}
}
}
}

class RemoteSetupDomain: MarshalByRefObject
{
public RemoteSetupDomain ()
{
// ensure types from this assembly passed to this domain from the main domain
// can be resolved even though we're in the LoadFrom context
AppDomain.CurrentDomain.AssemblyResolve += (o, a) => {
var asm = typeof(RemoteSetupDomain).Assembly;
return a.Name == asm.FullName? asm : null;
};
}

public override object InitializeLifetimeService ()
{
return null;
Expand Down

0 comments on commit 1efa795

Please sign in to comment.