19 December, 2011
0 Comments
1 category
When a assembly is not found, when using the standard probing method, an assembly resolve event is fired, allowing to load the assembly from a different file system path:
public void Test() { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromSameFolder); } public static Assembly LoadFromSameFolder(object sender, ResolveEventArgs args) { string folderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string assemblyPath = Path.Combine(folderPath, string.Format("{0}.dll", new AssemblyName(args.Name).Name)); if (!File.Exists(assemblyPath)) { assemblyPath = Path.Combine(folderPath, string.Format("{0}.exe", new AssemblyName(args.Name).Name)); if (!File.Exists(assemblyPath)) { return null; } } Assembly assembly = Assembly.LoadFrom(assemblyPath); return assembly; }
Tags: C#
Category: Uncategorized
Hi
I have a plugin based WPF application. Assemblies loaded during XAML parsing does not trigger the AsemblyResolve event.
Setting the probing path using AppendPrivatePath on CurrentDomain makes it work, but this function is marked as Obsolete.