public ExtensionEntry Load(ExtensionDescriptor descriptor) { if (!descriptor.Location.StartsWith("Core")) { return(null); } var directory = _fileSystem.GetDirectoryInfo("Core"); using (_loaderContainer.AddLoader(_extensionAssemblyLoader.WithPath(directory.FullName))) { var assembly = Assembly.Load(new AssemblyName(CoreAssemblyName)); if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Loaded referenced extension \"{0}\": assembly name=\"{1}\"", descriptor.Name, assembly.FullName); } return(new ExtensionEntry { Descriptor = descriptor, Assembly = assembly, ExportedTypes = assembly.ExportedTypes.Where(x => IsTypeFromModule(x, descriptor)) }); } }
public ExtensionEntry Load(ExtensionDescriptor descriptor) { if (!ExtensionsSearchPaths.Contains(descriptor.Location)) { return(null); } var plocation = _hostEnvironment.MapPath(descriptor.Location); using (_loaderContainer.AddLoader(_extensionAssemblyLoader.WithPath(plocation))) { try { var assembly = Assembly.Load(new AssemblyName(descriptor.Id)); if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Loaded referenced extension \"{0}\": assembly name=\"{1}\"", descriptor.Name, assembly.FullName); } return(new ExtensionEntry { Descriptor = descriptor, Assembly = assembly, ExportedTypes = assembly.ExportedTypes }); } catch (System.Exception ex) { _logger.LogError(string.Format("Error trying to load extension {0}", descriptor.Id), ex); throw; } } }
public static IEnumerable <Assembly> GetAssemblies(string path, IAssemblyLoaderContainer assemblyLoaderContainer, IAssemblyLoadContextAccessor assemblyLoadContextAccessor, ILibraryManager libraryManager) { List <Assembly> assemblies = new List <Assembly>(); IAssemblyLoadContext assemblyLoadContext = assemblyLoadContextAccessor.Default; using (assemblyLoaderContainer.AddLoader(new DirectoryAssemblyLoader(path, assemblyLoadContext))) { foreach (string extensionPath in Directory.EnumerateFiles(path, "*.dll")) { string extensionFilename = Path.GetFileNameWithoutExtension(extensionPath); assemblies.Add(assemblyLoadContext.Load(extensionFilename)); } } // We must not load all of the assemblies foreach (Library library in libraryManager.GetLibraries()) { if (AssemblyManager.IsCandidateLibrary(libraryManager, library)) { assemblies.AddRange(library.Assemblies.Select(an => assemblyLoadContext.Load(an))); } } return(assemblies); }
public AssemblyCache(ILibraryManager manager, IAssemblyLoadContextAccessor accessor, IAssemblyLoaderContainer container, IApplicationEnvironment environment) { _libraryManager = manager; _environment = environment; _loadContext = accessor.GetLoadContext(typeof (Program).GetTypeInfo().Assembly); Loader = new DirectoryLookupAssemblyLoader(_loadContext); _loaderRegistration = container.AddLoader(Loader); }
private int RunTests(TestOptions options) { if (options.Sink != null) { var parts = options.Sink.Split('|'); var packagesPath = Path.GetFullPath(parts[0]); var dependencyResolver = new NuGetDependencyResolver(packagesPath); var lib = dependencyResolver.GetDescription(new LibraryRange { Name = parts[1] }, _environment.RuntimeFramework); dependencyResolver.Initialize(new[] { lib }, _environment.RuntimeFramework); var dependencyLoader = new NuGetAssemblyLoader(_loadContextAccessor, dependencyResolver); var referenceLoader = new ReferenceLoader(_frameworkReferenceResolver, _environment.RuntimeFramework); using (_container.AddLoader(dependencyLoader)) using (_container.AddLoader(referenceLoader)) using (var context = _loadContextFactory.Create()) { var assembly = dependencyLoader.Load(parts[1], context); var locator = assembly.GetCustomAttributes() .OfType <ITestSinkFactory>() .FirstOrDefault(); if (locator == null) { throw new InvalidOperationException($"No assembly attribute found that implements the interface 'ITestSinkLocator' in the assembly ${assembly.GetName().Name}"); } var testServices = new ServiceProvider(_services); testServices.Add(typeof(ITestSinkFactory), locator); return(RunTestAssembly(options, ".", _container, testServices) ? 0 : -1); } } else { return(RunTestAssembly(options, ".", _container, _services) ? 0 : -1); } }
private Assembly Load(AssemblyName assemblyName) { var assembly = Assembly.Load(assemblyName); if (assembly != null) { return(assembly); } using (_loaderContainer.AddLoader(new ExtensionAssemblyLoader(string.Empty, _serviceProvider))) { return(Assembly.Load(assemblyName)); } }
private Assembly Load(AssemblyName assemblyName) { var assembly = Assembly.Load(assemblyName); if (assembly != null) { return(assembly); } using (_loaderContainer.AddLoader(_extensionAssemblyLoader)) { return(Assembly.Load(assemblyName)); } }
public void LoadAssemblies() { _componentsAssemblies = new List <Assembly>(); var componentsDirectoryPath = _componentsPathProvider.GetComponentsDirectoryPath(); var assemblyLoadContext = _assemblyLoadContextAccessor.Default; using (_assemblyLoaderContainer.AddLoader(new GoofyPlatformAbstractionsAssemblyLoader(assemblyLoadContext))) { foreach (var componentDirectory in Directory.EnumerateDirectories(componentsDirectoryPath).Select(dir => new DirectoryInfo(dir))) { var componentName = componentDirectory.Name; //Si la carpeta contiene un project.json, se va a asumir que es un dependencia de tipo proyecto //var projectJsonPath = Path.Combine(componentDirectory.FullName, "project.json"); //var dllPath = Path.Combine(componentDirectory.FullName, string.Format("{0}.dll", componentName)); //if (File.Exists(projectJsonPath)) //{ // _componentsAssemblies.Add(assemblyLoadContext.Load(projectJsonPath)); //} var componentDllPath = Path.Combine(componentDirectory.FullName, string.Format("{0}{1}", componentName, ComponentExtension)); if (File.Exists(componentDllPath)) { _componentsAssemblies.Add(assemblyLoadContext.LoadFile(componentDllPath)); _logger.LogInformation("La Componente \"{0}\", fue cargada satisfactoriamente.", componentName); } else { _logger.LogWarning("La carpeta \"{0}\" situada en \"{1}\" no es un Component válida.", componentName, componentDirectory.FullName); } } } //foreach (var componentPath in Directory.GetDirectories(componentsDirectoryPath, ComponentDirectoryPrefixPattern, SearchOption.TopDirectoryOnly)) //{ // var dllPath = string.Format("{0}\\{1}{2}", componentPath, new DirectoryInfo(componentPath).Name, ComponentExtension); // Assembly currentAssembly; // AssemblyName assemblyName; // try // { // assemblyName = AssemblyName.GetAssemblyName(dllPath); // currentAssembly = Assembly.Load(assemblyName);//cambiar esta línea por appDomain.Load(assemblyName) en caso de que se quiera cargar el assembly al dominio vigente // _componentsAssemblies.Add(currentAssembly); // } // catch (TargetInvocationException e) // { // //TODO:agregar a los logs ComponenteInválida porque no presenta una dll. // continue; // } //} }
private IEnumerable <Assembly> GetAssembliesInFolder(DirectoryInfo binPath) { List <Assembly> assemblies = new List <Assembly>(); var loadContext = loadContextAccessor.Default; assemblyLoaderContainer.AddLoader(new PluginDirectoryLoader(binPath, loadContext)); foreach (var fileSystemInfo in binPath.GetFileSystemInfos("*.dll")) { assemblies.Add(loadContext.Load(AssemblyName.GetAssemblyName(fileSystemInfo.FullName))); } return(assemblies); }
public IDisposable AddLoaders(IAssemblyLoaderContainer container) { var disposables = new List<IDisposable>(); foreach (var loader in _loaders) { disposables.Add(container.AddLoader(loader)); } return new DisposableAction(() => { foreach (var d in Enumerable.Reverse(disposables)) { d.Dispose(); } }); }
public IDisposable AddLoaders(IAssemblyLoaderContainer container) { var disposables = new List <IDisposable>(); foreach (var loader in _loaders) { disposables.Add(container.AddLoader(loader)); } return(new DisposableAction(() => { foreach (var d in Enumerable.Reverse(disposables)) { d.Dispose(); } })); }
public ExtensionEntry Load(ExtensionDescriptor descriptor) { var plocation = _virtualPathProvider.MapPath(descriptor.Location); using (_loaderContainer.AddLoader(new ExtensionAssemblyLoader(plocation, _serviceProvider))) { var assembly = Assembly.Load(new AssemblyName(descriptor.Id)); _logger.WriteInformation("Loaded referenced extension \"{0}\": assembly name=\"{1}\"", descriptor.Name, assembly.FullName); return(new ExtensionEntry { Descriptor = descriptor, Assembly = assembly, ExportedTypes = assembly.ExportedTypes }); } }
public static IEnumerable<Assembly> LoadAssemblies(string path, IAssemblyLoaderContainer assemblyLoaderContainer, IAssemblyLoadContextAccessor assemblyLoadContextAccessor) { List<Assembly> assemblies = new List<Assembly>(); IAssemblyLoadContext assemblyLoadContext = assemblyLoadContextAccessor.Default; using (assemblyLoaderContainer.AddLoader(new DirectoryAssemblyLoader(path, assemblyLoadContext))) { foreach (string extensionPath in Directory.EnumerateFiles(path, "*.dll")) { string extensionFilename = Path.GetFileNameWithoutExtension(extensionPath); assemblies.Add(assemblyLoadContext.Load(extensionFilename)); } } return assemblies; }
public static IEnumerable <Assembly> LoadAssemblies(string path, IAssemblyLoaderContainer assemblyLoaderContainer, IAssemblyLoadContextAccessor assemblyLoadContextAccessor) { List <Assembly> assemblies = new List <Assembly>(); IAssemblyLoadContext assemblyLoadContext = assemblyLoadContextAccessor.Default; using (assemblyLoaderContainer.AddLoader(new DirectoryAssemblyLoader(path, assemblyLoadContext))) { foreach (string extensionPath in Directory.EnumerateFiles(path, "*.dll")) { string extensionFilename = Path.GetFileNameWithoutExtension(extensionPath); assemblies.Add(assemblyLoadContext.Load(extensionFilename)); } } return(assemblies); }
/// <summary> /// Returns assemblies loaded from /bin folders inside of App_Plugins /// </summary> /// <param name="binPath"></param> /// <returns></returns> private IEnumerable <Assembly> GetAssembliesInFolder(DirectoryInfo binPath) { // Use the default load context var loadContext = _loadContextAccessor.Default; // Add the loader to the container so that any call to Assembly.Load // will call the load context back (if it's not already loaded) using (_assemblyLoaderContainer.AddLoader( new DirectoryLoader(binPath, loadContext))) { foreach (var fileSystemInfo in binPath.GetFileSystemInfos("*.dll")) { //// In theory you should be able to use Assembly.Load() here instead //var assembly1 = Assembly.Load(AssemblyName.GetAssemblyName(fileSystemInfo.FullName)); var assembly2 = loadContext.Load(AssemblyName.GetAssemblyName(fileSystemInfo.FullName)); yield return(assembly2); } } }
public ExtensionEntry Load(ExtensionDescriptor descriptor) { if (!descriptor.Location.StartsWith("~/Core/")) { return(null); } var plocation = _virtualPathProvider.MapPath("~/Core"); using (_loaderContainer.AddLoader(new ExtensionAssemblyLoader(plocation, _serviceProvider))) { var assembly = Assembly.Load(new AssemblyName(CoreAssemblyName)); Logger.Information("Loaded referenced extension \"{0}\": assembly name=\"{1}\"", descriptor.Name, assembly.FullName); return(new ExtensionEntry { Descriptor = descriptor, Assembly = assembly, ExportedTypes = assembly.ExportedTypes.Where(x => IsTypeFromModule(x, descriptor)) }); } }
private IDisposable CreateLoaders(IAssemblyLoaderContainer loaderContainer, IAssemblyLoadContextAccessor loadContextAccessor, DependencyManager dependencies) { var loaderCleanup = new DisposableList(); foreach (var loaderFactory in _loaderFactories) { // Create the loader var loader = loaderFactory.Create( TargetFramework, loadContextAccessor, dependencies); // Attach it to the container and track it for clean-up if (Log.IsEnabled(LogLevel.Verbose)) { Log.LogVerbose($"Registering {loader.GetType().Name}"); } loaderCleanup.Add(loaderContainer.AddLoader(loader)); } return(loaderCleanup); }
public ExtensionEntry Load(ExtensionDescriptor descriptor) { if (!ExtensionsVirtualPathPrefixes.Contains(descriptor.Location)) { return(null); } var plocation = _virtualPathProvider.MapPath(descriptor.Location); using (_loaderContainer.AddLoader(_extensionAssemblyLoader.WithPath(plocation))) { var assembly = Assembly.Load(new AssemblyName(descriptor.Id)); Logger.Information("Loaded referenced extension \"{0}\": assembly name=\"{1}\"", descriptor.Name, assembly.FullName); return(new ExtensionEntry { Descriptor = descriptor, Assembly = assembly, ExportedTypes = assembly.ExportedTypes }); } }
public IDisposable AddLoaders(IAssemblyLoaderContainer container) { var loaders = new[] { typeof(ProjectAssemblyLoader), typeof(NuGetAssemblyLoader), }; var disposables = new List<IDisposable>(); foreach (var loaderType in loaders) { var loader = (IAssemblyLoader)ActivatorUtilities.CreateInstance(ServiceProvider, loaderType); disposables.Add(container.AddLoader(loader)); } return new DisposableAction(() => { foreach (var d in Enumerable.Reverse(disposables)) { d.Dispose(); } }); }
public static IEnumerable<Assembly> GetAssemblies(string path, IAssemblyLoaderContainer assemblyLoaderContainer, IAssemblyLoadContextAccessor assemblyLoadContextAccessor, ILibraryManager libraryManager) { List<Assembly> assemblies = new List<Assembly>(); IAssemblyLoadContext assemblyLoadContext = assemblyLoadContextAccessor.Default; using (assemblyLoaderContainer.AddLoader(new DirectoryAssemblyLoader(path, assemblyLoadContext))) { foreach (string extensionPath in Directory.EnumerateFiles(path, "*.dll")) { string extensionFilename = Path.GetFileNameWithoutExtension(extensionPath); assemblies.Add(assemblyLoadContext.Load(extensionFilename)); } } // We must not load all of the assemblies foreach (Library library in libraryManager.GetLibraries()) if (AssemblyManager.IsCandidateLibrary(libraryManager, library)) assemblies.AddRange(library.Assemblies.Select(an => assemblyLoadContext.Load(an))); return assemblies; }
public IDisposable AddLoaders(IAssemblyLoaderContainer container) { var loaders = new[] { typeof(ProjectAssemblyLoader), typeof(NuGetAssemblyLoader), }; var disposables = new List <IDisposable>(); foreach (var loaderType in loaders) { var loader = (IAssemblyLoader)ActivatorUtilities.CreateInstance(ServiceProvider, loaderType); disposables.Add(container.AddLoader(loader)); } return(new DisposableAction(() => { foreach (var d in Enumerable.Reverse(disposables)) { d.Dispose(); } })); }
private List<Assembly> LoadAssembliesFrom(string modulesDirectory, IAssemblyLoaderContainer assemblyLoaderContainer, IAssemblyLoadContextAccessor loadContextAccessor) { var assemblies = new List<Assembly>(); var loadContext = _assemblyLoadContextAccessor.GetLoadContext(typeof(Startup).GetTypeInfo().Assembly); using (assemblyLoaderContainer.AddLoader(new DirectoryLoader(modulesDirectory, loadContext))) { foreach (var modulePath in Directory.EnumerateFiles(modulesDirectory, "*.dll")) { var name = Path.GetFileNameWithoutExtension(modulePath); assemblies.Add(loadContext.Load(name)); } } return assemblies; }