Exemple #1
0
        public virtual Assembly ResolveAssembly(AssemblyName name)
        {
            lock (_lock)
            {
                var cancelArgs = new AssemblyResolveCancelEventArgs(name);
                this.OnAssemblyResolve(cancelArgs);
                if (!cancelArgs.Cancel)
                {
                    if (!this.AssemblyResolveFailed.Any(n => n.Name.Equals(name.Name)))
                    {
                        var assemblies =
                            this.Modules.SelectMany(
                                m => m.Assemblies.Where(d => d.Assembly.GetName().Name.Equals(name.Name))).ToList();
                        if (assemblies.Any())
                        {
                            return(assemblies.First().Assembly);
                        }

                        foreach (var module in this.Modules.Where(m => m.AllowAssemblyResolve))
                        {
                            var assemblyInfo = module.ResolveAssembly(name);
                            if (assemblyInfo != null)
                            {
                                var args = new AssemblyResolvedEventArgs(name, module, assemblyInfo);
                                this.OnAssemblyResolved(args);
                                return(assemblyInfo.Assembly);
                            }
                        }
                        this.assemblyResolveFailed.Add(name);
                    }
                    return(null);
                }
                return(cancelArgs.Assembly);
            }
        }
Exemple #2
0
 protected void OnAssemblyResolve(AssemblyResolveCancelEventArgs args)
 {
     this.AssemblyResolve?.Invoke(this, args);
 }