我通常会做这样的事情(在您的应用程序早期的某个地方注册 AssemblyResolve,例如在 Program.cs 或 App.xaml.cs 中):
//Since we'll be dynamically loading assemblies at runtime, we need to add an appropriate resolution path
//Otherwise weird things like failing to instantiate TypeConverters will happen
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var domain = (AppDomain)sender;
foreach (var assembly in domain.GetAssemblies())
{
if (assembly.FullName == args.Name)
return assembly;
}
return null;
}