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

Commit 1efa795

Browse files
committed
Make scan domain work in LoadFrom context
1 parent ecb7dd9 commit 1efa795

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

Mono.Addins/Mono.Addins.Database/SetupDomain.cs

+24-3
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,23 @@ public void GetAddinDescription (IProgressStatus monitor, AddinRegistry registry
6262
ReleaseDomain ();
6363
}
6464
}
65-
65+
66+
// ensure types from this assembly returned to this domain from the remote domain can
67+
// be resolved even if we're in the LoadFrom context
68+
static System.Reflection.Assembly MonoAddinsAssemblyResolve(object sender, ResolveEventArgs args)
69+
{
70+
var asm = typeof(SetupDomain).Assembly;
71+
return args.Name == asm.FullName? asm : null;
72+
}
73+
6674
RemoteSetupDomain GetDomain ()
6775
{
6876
lock (this) {
6977
if (useCount++ == 0) {
78+
AppDomain.CurrentDomain.AssemblyResolve += MonoAddinsAssemblyResolve;
7079
domain = AppDomain.CreateDomain ("SetupDomain", null, AppDomain.CurrentDomain.SetupInformation);
71-
remoteSetupDomain = (RemoteSetupDomain) domain.CreateInstanceFromAndUnwrap (typeof(RemoteSetupDomain).Assembly.Location, typeof(RemoteSetupDomain).FullName);
80+
var type = typeof(RemoteSetupDomain);
81+
remoteSetupDomain = (RemoteSetupDomain) domain.CreateInstanceFromAndUnwrap (type.Assembly.Location, type.FullName);
7282
}
7383
return remoteSetupDomain;
7484
}
@@ -81,13 +91,24 @@ void ReleaseDomain ()
8191
AppDomain.Unload (domain);
8292
domain = null;
8393
remoteSetupDomain = null;
94+
AppDomain.CurrentDomain.AssemblyResolve -= MonoAddinsAssemblyResolve;
8495
}
8596
}
8697
}
8798
}
88-
99+
89100
class RemoteSetupDomain: MarshalByRefObject
90101
{
102+
public RemoteSetupDomain ()
103+
{
104+
// ensure types from this assembly passed to this domain from the main domain
105+
// can be resolved even though we're in the LoadFrom context
106+
AppDomain.CurrentDomain.AssemblyResolve += (o, a) => {
107+
var asm = typeof(RemoteSetupDomain).Assembly;
108+
return a.Name == asm.FullName? asm : null;
109+
};
110+
}
111+
91112
public override object InitializeLifetimeService ()
92113
{
93114
return null;

0 commit comments

Comments
 (0)