예제 #1
0
        public Assembly InvokeResolveAssembly(string fullAssemblyName)
        {
            AssemblyResolveEventArgs resolveArgs = new AssemblyResolveEventArgs(fullAssemblyName);

            this.AssemblyResolve(this, resolveArgs);
            return(resolveArgs.ResolvedAssembly);
        }
        private void assemblyLoader_AssemblyResolve(object sender, AssemblyResolveEventArgs args)
        {
            // Early-out, if the Assembly has already been resolved
            if (args.IsResolved)
            {
                return;
            }

            // Search for editor plugins that haven't been loaded yet, and load them first.
            // This is required to satisfy dependencies while loading plugins, since
            // we can't know which one requires which beforehand.
            foreach (string libFile in this.AssemblyLoader.AvailableAssemblyPaths)
            {
                if (!libFile.EndsWith(".editor.dll", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                string libName = PathOp.GetFileNameWithoutExtension(libFile);
                if (libName.Equals(args.AssemblyName, StringComparison.OrdinalIgnoreCase))
                {
                    EditorPlugin plugin = this.LoadPlugin(libFile);
                    if (plugin != null)
                    {
                        args.Resolve(plugin.PluginAssembly);
                        return;
                    }
                }
            }
        }
예제 #3
0
        private void AssemblyLoader_AssemblyResolve(object sender, AssemblyResolveEventArgs args)
        {
            // Early-out, if the Assembly has already been resolved
            if (args.IsResolved)
            {
                return;
            }

            // Search for core plugins that haven't been loaded yet, and load them first.
            // This is required to satisfy dependencies while loading plugins, since
            // we can't know which one requires which beforehand.
            foreach (string libFile in this.AssemblyLoader.AvailableAssemblyPaths)
            {
                if (!libFile.EndsWith(".core.dll", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                string libName = PathOp.GetFileNameWithoutExtension(libFile);
                if (libName.Equals(args.AssemblyName, StringComparison.OrdinalIgnoreCase))
                {
                    CorePlugin plugin = this.LoadPlugin(libFile);
                    if (plugin != null)
                    {
                        args.Resolve(plugin.PluginAssembly);
                        return;
                    }
                }
            }

            // Search for other libraries that might be located inside the plugin directory
            foreach (string libFile in this.AssemblyLoader.AvailableAssemblyPaths)
            {
                // Don't load editor (or any other) plugins here, only auxilliary libs allowed
                if (libFile.EndsWith(".editor.dll", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                string libName = PathOp.GetFileNameWithoutExtension(libFile);
                if (libName.Equals(args.AssemblyName, StringComparison.OrdinalIgnoreCase))
                {
                    Assembly assembly = this.LoadAuxilliaryLibrary(libFile, false);
                    if (assembly != null)
                    {
                        args.Resolve(assembly);
                        return;
                    }
                }
            }
        }
예제 #4
0
        private void assemblyLoader_AssemblyResolve(object sender, AssemblyResolveEventArgs args)
        {
            // Early-out, if the Assembly has already been resolved
            if (args.IsResolved)
            {
                return;
            }

            // Are we searching for an already loaded plugin?
            if (this.pluginRegistry.TryGetValue(args.AssemblyName, out T plugin))
            {
                args.Resolve(plugin.PluginAssembly);
                return;
            }
        }
예제 #5
0
        private Assembly CurrentDomainAssemblyResolve(object sender, AssemblyResolveEventArgs args)
        {
            var assemblyName = new AssemblyName(args.Name);

            Assembly assembly = null;

            lock (this.resolvedAssemblies)
            {
                try
                {
                    EqtTrace.Verbose("CurrentDomainAssemblyResolve: Resolving assembly '{0}'.", args.Name);

                    if (this.resolvedAssemblies.TryGetValue(args.Name, out assembly))
                    {
                        return(assembly);
                    }

                    // Put it in the resolved assembly so that if below Assembly.Load call
                    // triggers another assembly resolution, then we don't end up in stack overflow
                    this.resolvedAssemblies[args.Name] = null;

                    assembly = Assembly.Load(assemblyName);

                    // Replace the value with the loaded assembly
                    this.resolvedAssemblies[args.Name] = assembly;

                    return(assembly);
                }
                finally
                {
                    if (assembly == null)
                    {
                        EqtTrace.Verbose("CurrentDomainAssemblyResolve: Failed to resolve assembly '{0}'.", args.Name);
                    }
                }
            }
        }
예제 #6
0
        private Assembly OnResolve(object sender, AssemblyResolveEventArgs args)
        {
            if (string.IsNullOrEmpty(args?.Name))
            {
                Debug.Fail("AssemblyResolver.OnResolve: args.Name is null or empty.");
                return(null);
            }

            if (this.searchDirectories == null || this.searchDirectories.Count == 0)
            {
                EqtTrace.Info("AssemblyResolver.OnResolve: {0}: There are no search directories, returning.", args.Name);
                return(null);
            }

            EqtTrace.Info("AssemblyResolver.OnResolve: {0}: Resolving assembly.", args.Name);

            // args.Name is like: "Microsoft.VisualStudio.TestTools.Common, Version=[VersionMajor].0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
            lock (this.resolvedAssemblies)
            {
                if (this.resolvedAssemblies.TryGetValue(args.Name, out var assembly))
                {
                    EqtTrace.Info("AssemblyResolver.OnResolve: {0}: Resolved from cache.", args.Name);
                    return(assembly);
                }

                AssemblyName requestedName = null;
                try
                {
                    // Can throw ArgumentException, FileLoadException if arg is empty/wrong format, etc. Should not return null.
                    requestedName = new AssemblyName(args.Name);
                }
                catch (Exception ex)
                {
                    if (EqtTrace.IsInfoEnabled)
                    {
                        EqtTrace.Info("AssemblyResolver.OnResolve: {0}: Failed to create assemblyName. Reason:{1} ", args.Name, ex);
                    }

                    this.resolvedAssemblies[args.Name] = null;
                    return(null);
                }

                Debug.Assert(requestedName != null && !string.IsNullOrEmpty(requestedName.Name), "AssemblyResolver.OnResolve: requested is null or name is empty!");

                foreach (var dir in this.searchDirectories)
                {
                    if (string.IsNullOrEmpty(dir))
                    {
                        continue;
                    }

                    EqtTrace.Info("AssemblyResolver.OnResolve: {0}: Searching in: '{1}'.", args.Name, dir);

                    foreach (var extension in SupportedFileExtensions)
                    {
                        var assemblyPath = Path.Combine(dir, requestedName.Name + extension);
                        try
                        {
                            if (!File.Exists(assemblyPath))
                            {
                                EqtTrace.Info("AssemblyResolver.OnResolve: {0}: Assembly path does not exist: '{1}', returning.", args.Name, assemblyPath);

                                continue;
                            }

                            AssemblyName foundName = this.platformAssemblyLoadContext.GetAssemblyNameFromPath(assemblyPath);

                            if (!this.RequestedAssemblyNameMatchesFound(requestedName, foundName))
                            {
                                EqtTrace.Info("AssemblyResolver.OnResolve: {0}: File exists but version/public key is wrong. Try next extension.", args.Name);
                                continue;   // File exists but version/public key is wrong. Try next extension.
                            }

                            EqtTrace.Info("AssemblyResolver.OnResolve: {0}: Loading assembly '{1}'.", args.Name, assemblyPath);

                            assembly = this.platformAssemblyLoadContext.LoadAssemblyFromPath(assemblyPath);
                            this.resolvedAssemblies[args.Name] = assembly;

                            EqtTrace.Info("AssemblyResolver.OnResolve: Resolved assembly: {0}, from path: {1}", args.Name, assemblyPath);

                            return(assembly);
                        }
                        catch (FileLoadException ex)
                        {
                            EqtTrace.Error("AssemblyResolver.OnResolve: {0}: Failed to load assembly. Reason:{1} ", args.Name, ex);

                            // Re-throw FileLoadException, because this exception means that the assembly
                            // was found, but could not be loaded. This will allow us to report a more
                            // specific error message to the user for things like access denied.
                            throw;
                        }
                        catch (Exception ex)
                        {
                            // For all other exceptions, try the next extension.
                            EqtTrace.Info("AssemblyResolver.OnResolve: {0}: Failed to load assembly. Reason:{1} ", args.Name, ex);
                        }
                    }
                }

                if (EqtTrace.IsInfoEnabled)
                {
                    EqtTrace.Info("AssemblyResolver.OnResolve: {0}: Failed to load assembly.", args.Name);
                }

                this.resolvedAssemblies[args.Name] = null;
                return(null);
            }
        }