protected override Assembly LoadAssembly(string filePath, AssemblyName name) { bool registered = _AssemblyDependencyTracker.RegisterReferencedAssembly(name); try { return(base.LoadAssembly(filePath, name)); } catch { if (registered) { _AssemblyDependencyTracker.UnregisterReferencedAssembly(name); } throw; } }
Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { if (_AssemblyDependencyTracker.IsAssemblyResolutionInhibited(args.RequestingAssembly)) { return(null); } var assemblyName = new AssemblyName(args.Name); var assemblyVersion = assemblyName.Version; assemblyName.Version = null; if (_BindingRedirects.TryGetValue(assemblyName.ToString(), out var bindingRedirect) && bindingRedirect.Matches(assemblyVersion) && assemblyVersion != bindingRedirect.To) { assemblyName.Version = bindingRedirect.To; bool assemblyRegistered = _AssemblyDependencyTracker.RegisterReferencedAssembly(assemblyName); Assembly assembly = null; try { assembly = Assembly.Load(assemblyName); } finally { if (assembly == null && assemblyRegistered) { _AssemblyDependencyTracker.UnregisterReferencedAssembly(assemblyName); } } return(assembly); } return(null); }