LoadAssembly() public static méthode

public static LoadAssembly ( string name ) : Assembly
name string
Résultat System.Reflection.Assembly
Exemple #1
0
        public static Assembly AddReference(string name)
        {
            AssemblyManager.UpdatePath();
            Assembly assembly = null;

            assembly = AssemblyManager.FindLoadedAssembly(name);
            if (assembly == null)
            {
                assembly = AssemblyManager.LoadAssemblyPath(name);
            }
            if (assembly == null)
            {
                assembly = AssemblyManager.LoadAssembly(name);
            }
            if (assembly == null)
            {
                assembly = AssemblyManager.LoadAssemblyFullPath(name);
            }
            if (assembly == null)
            {
                throw new FileNotFoundException($"Unable to find assembly '{name}'.");
            }

            return(assembly);
        }
        public static Assembly AddReference(string name)
        {
            AssemblyManager.UpdatePath();
            Assembly assembly = null;

            assembly = AssemblyManager.FindLoadedAssembly(name);
            if (assembly == null)
            {
                assembly = AssemblyManager.LoadAssemblyPath(name);
            }
            if (assembly == null)
            {
                assembly = AssemblyManager.LoadAssembly(name);
            }
            if (assembly == null)
            {
                assembly = AssemblyManager.LoadAssemblyFullPath(name);
            }
            if (assembly == null)
            {
                string msg = String.Format("Unable to find assembly '{0}'.", name);
                throw new System.IO.FileNotFoundException(msg);
            }

            return(assembly);
        }
Exemple #3
0
        public static Assembly AddReference(string name)
        {
            AssemblyManager.UpdatePath();
            Assembly assembly = null;

            assembly = AssemblyManager.FindLoadedAssembly(name);
            if (assembly == null)
            {
                assembly = AssemblyManager.LoadAssemblyPath(name);
            }
            if (assembly == null)
            {
                assembly = AssemblyManager.LoadAssembly(name);
            }
            if (assembly == null)
            {
                assembly = AssemblyManager.LoadAssemblyFullPath(name);
            }
            if (System.IO.File.Exists(name))
            {
                var zone = System.Security.Policy.Zone.CreateFromUrl(name);
                if (zone.SecurityZone != System.Security.SecurityZone.MyComputer)
                {
                    throw new Exception($"File is blocked (NTFS Security)");
                }
            }
            if (assembly == null)
            {
                throw new FileNotFoundException($"Unable to find assembly '{name}'.");
            }

            return(assembly);
        }
        public static Assembly AddReference(string name)
        {
            AssemblyManager.UpdatePath();
            var      origNs   = AssemblyManager.GetNamespaces();
            Assembly assembly = null;

            assembly = AssemblyManager.FindLoadedAssembly(name);
            if (assembly == null)
            {
                assembly = AssemblyManager.LoadAssemblyPath(name);
            }
            if (assembly == null && AssemblyManager.TryParseAssemblyName(name) is { } parsedName)
            {
                assembly = AssemblyManager.LoadAssembly(parsedName);
            }
            if (assembly == null)
            {
                assembly = AssemblyManager.LoadAssemblyFullPath(name);
            }
            if (assembly == null)
            {
                throw new FileNotFoundException($"Unable to find assembly '{name}'.");
            }
            // Classes that are not in a namespace needs an extra nudge to be found.
            ImportHook.UpdateCLRModuleDict();

            // A bit heavyhanded, but we can't use the AssemblyManager's AssemblyLoadHandler
            // method because it may be called from other threads, leading to deadlocks
            // if it is called while Python code is executing.
            var currNs = AssemblyManager.GetNamespaces().Except(origNs);

            foreach (var ns in currNs)
            {
                ImportHook.AddNamespaceWithGIL(ns);
            }
            return(assembly);
        }