Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
 protected void OnAssemblyResolved(AssemblyResolvedEventArgs args)
 {
     this.AssemblyResolved?.Invoke(this, args);
 }