forked from msawczyn/EFDesigner2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Consuming assemblies.linq
53 lines (40 loc) · 1.3 KB
/
Consuming assemblies.linq
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<Query Kind="Statements" />
string pathToAssembly = @"C:\Code\ClientProjects\AWH\IncludeFitness-Cloud\Include.Repository\bin\Debug\Include.Repository.dll";
AssemblyName assemblyName = AssemblyName.GetAssemblyName(pathToAssembly);
string assemblyDirectory = Path.GetDirectoryName(pathToAssembly);
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += ResolveAssembly;
Assembly loadedAssembly = Assembly.ReflectionOnlyLoadFrom(pathToAssembly);
IEnumerable<Type> theTypes = loadedAssembly.GetExportedTypes().ToList();
foreach (Type type in theTypes)
{
Console.WriteLine((type.BaseType?.FullName ?? "") + "\t\t" + type.FullName);
}
System.Reflection.Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
Assembly dep = null;
try
{
/// Try to load the dependency from the same location
/// than the original assembly. We need to keep track
/// about the source directory.
dep = Assembly.ReflectionOnlyLoadFrom(Path.Combine(assemblyDirectory, args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll"));
if (dep != null)
return dep;
}
catch (System.IO.FileNotFoundException)
{
dep = null;
}
try
{
/// Try to load from the GAC.
dep = Assembly.ReflectionOnlyLoad(args.Name);
if (dep != null)
return dep;
}
catch (System.IO.FileLoadException)
{
dep = null;
}
return null;
}