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);
        }
 protected override bool IsAssemblyResolutionInhibited(ResolveEventArgs args) =>
 _AssemblyDependencyTracker.IsAssemblyResolutionInhibited(args.RequestingAssembly);