-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppDomainResolver.cs
39 lines (32 loc) · 1.06 KB
/
AppDomainResolver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Limes
{
internal class AppDomainResolver : MarshalByRefObject
{
private readonly AppDomain _appDomain;
public AppDomainResolver(AppDomain appDomain)
{
_appDomain = appDomain;
}
public string Resolve(string name)
{
// check if the assembly has already been loaded in the parent domain
// this is important for when an assembly is loaded directly into the parent domain, e.g. in linqpad
Assembly assembly = _appDomain.GetAssemblies().FirstOrDefault(x => x.FullName == name);
if (assembly != null)
{
return assembly.Location;
}
// try to resolve using reflection only
assembly = Assembly.ReflectionOnlyLoad(name);
if (assembly != null)
{
return assembly.Location;
}
return null;
}
}
}