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 static T CreateService <T>(IServiceProvider sp, IAssemblyLoadContext loadContext, TypeInformation typeInfo) { var assembly = loadContext.Load(typeInfo.AssemblyName); var type = assembly.GetType(typeInfo.TypeName); return((T)ActivatorUtilities.CreateInstance(sp, type)); }
public override Assembly LoadAssembly(AssemblyName assemblyName) { try { return(_defaultContext.Load(assemblyName)); } catch (FileNotFoundException) { return(LoadWithoutDefault(assemblyName)); } }
public override Assembly LoadAssembly(AssemblyName assemblyName) { try { return(_defaultContext.Load(assemblyName)); } catch (FileNotFoundException) { return(_projectAssemblyLoader.Load(assemblyName, this) ?? _nugetAssemblyLoader.Load(assemblyName, this)); } }
public IProjectCompiler GetCompiler(TypeInformation provider, IAssemblyLoadContext loadContext) { // TODO: Optimize the default compiler case by using the default load context directly var services = new ServiceProvider(_context.Services); services.Add(typeof(IAssemblyLoadContext), loadContext); var assembly = loadContext.Load(provider.AssemblyName); var type = assembly.GetType(provider.TypeName); return (IProjectCompiler)ActivatorUtilities.CreateInstance(services, type); }
public IProjectCompiler GetCompiler(TypeInformation provider, IAssemblyLoadContext loadContext) { // TODO: Optimize the default compiler case by using the default load context directly var services = new ServiceProvider(_context.Services); services.Add(typeof(IAssemblyLoadContext), loadContext); var assembly = loadContext.Load(provider.AssemblyName); var type = assembly.GetType(provider.TypeName); return((IProjectCompiler)ActivatorUtilities.CreateInstance(services, type)); }
public override Assembly LoadAssembly(string name) { try { return(_defaultContext.Load(name)); } #if ASPNET50 catch (FileNotFoundException) #else catch (FileLoadException) #endif { return(_projectAssemblyLoader.Load(name, this) ?? _nugetAssemblyLoader.Load(name, this)); } }
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); }
private IEnumerable <TypeInfo> GetExportedTypesCore(AssemblyName assemblyName) { var assembly = _loadContext.Load(assemblyName.Name); return(assembly.ExportedTypes.Select(type => type.GetTypeInfo())); }
protected override IEnumerable <TypeInfo> GetExportedTypes(AssemblyName assemblyName) { var assembly = _assemblyLoadContext.Load(assemblyName.FullName); return(assembly.ExportedTypes.Select(type => type.GetTypeInfo())); }
public static Assembly Load(this IAssemblyLoadContext loadContext, string name) { return(loadContext.Load(new AssemblyName(name))); }
private PluginResponseMessage RegisterPlugin( PluginMessage message, IAssemblyLoadContext assemblyLoadContext) { var registerData = message.Data.ToObject <PluginRegisterData>(); var response = new RegisterPluginResponseMessage { MessageName = RegisterPluginMessageName }; var pluginId = message.PluginId; var registerDataTypeCacheKey = registerData.GetFullTypeCacheKey(); IPlugin plugin; Type pluginType; if (!_pluginTypeCache.TryGetValue(registerDataTypeCacheKey, out pluginType)) { try { Assembly assembly; if (!_assemblyCache.TryGetValue(registerData.AssemblyName, out assembly)) { assembly = assemblyLoadContext.Load(registerData.AssemblyName); } pluginType = assembly.GetType(registerData.TypeName); } catch (Exception exception) { response.Error = exception.Message; return(response); } } if (pluginType == null) { response.Error = Resources.FormatPlugin_TypeCouldNotBeLocatedInAssembly( pluginId, registerData.TypeName, registerData.AssemblyName); return(response); } else { // We build out a custom plugin service provider to add a PluginMessageBroker and // IAssemblyLoadContext to the potential services that can be used to construct an IPlugin. var pluginServiceProvider = new PluginServiceProvider( _hostServices, messageBroker: new PluginMessageBroker(pluginId, _sendMessageMethod)); plugin = ActivatorUtilities.CreateInstance(pluginServiceProvider, pluginType) as IPlugin; if (plugin == null) { response.Error = Resources.FormatPlugin_CannotProcessMessageInvalidPluginType( pluginId, pluginType.FullName, typeof(IPlugin).FullName); return(response); } } Debug.Assert(plugin != null); int resolvedProtocol; if (!registerData.Protocol.HasValue) { // Protocol wasn't provided, use the plugin's protocol. resolvedProtocol = plugin.Protocol; } else { // Client and plugin protocols are max values; meaning support is <= value. The goal in this method is // to return the maximum protocol supported by both parties (client and plugin). resolvedProtocol = Math.Min(registerData.Protocol.Value, plugin.Protocol); // Update the plugins protocol to be the resolved protocol. plugin.Protocol = resolvedProtocol; } _registeredPlugins[pluginId] = plugin; response.Protocol = resolvedProtocol; return(response); }
private PluginResponseMessage RegisterPlugin( PluginMessage message, IAssemblyLoadContext assemblyLoadContext) { var registerData = message.Data.ToObject<PluginRegisterData>(); var response = new RegisterPluginResponseMessage { MessageName = RegisterPluginMessageName }; var pluginId = message.PluginId; var registerDataTypeCacheKey = registerData.GetFullTypeCacheKey(); IPlugin plugin; Type pluginType; if (!_pluginTypeCache.TryGetValue(registerDataTypeCacheKey, out pluginType)) { try { Assembly assembly; if (!_assemblyCache.TryGetValue(registerData.AssemblyName, out assembly)) { assembly = assemblyLoadContext.Load(registerData.AssemblyName); } pluginType = assembly.GetType(registerData.TypeName); } catch (Exception exception) { response.Error = exception.Message; return response; } } if (pluginType == null) { response.Error = Resources.FormatPlugin_TypeCouldNotBeLocatedInAssembly( pluginId, registerData.TypeName, registerData.AssemblyName); return response; } else { // We build out a custom plugin service provider to add a PluginMessageBroker and // IAssemblyLoadContext to the potential services that can be used to construct an IPlugin. var pluginServiceProvider = new PluginServiceProvider( _hostServices, messageBroker: new PluginMessageBroker(pluginId, _sendMessageMethod)); plugin = ActivatorUtilities.CreateInstance(pluginServiceProvider, pluginType) as IPlugin; if (plugin == null) { response.Error = Resources.FormatPlugin_CannotProcessMessageInvalidPluginType( pluginId, pluginType.FullName, typeof(IPlugin).FullName); return response; } } Debug.Assert(plugin != null); int resolvedProtocol; if (!registerData.Protocol.HasValue) { // Protocol wasn't provided, use the plugin's protocol. resolvedProtocol = plugin.Protocol; } else { // Client and plugin protocols are max values; meaning support is <= value. The goal in this method is // to return the maximum protocol supported by both parties (client and plugin). resolvedProtocol = Math.Min(registerData.Protocol.Value, plugin.Protocol); // Update the plugins protocol to be the resolved protocol. plugin.Protocol = resolvedProtocol; } _registeredPlugins[pluginId] = plugin; response.Protocol = resolvedProtocol; return response; }
private PluginResponseMessage RegisterPlugin( PluginMessage message, IAssemblyLoadContext assemblyLoadContext) { var registerData = message.Data.ToObject<PluginRegisterData>(); var response = new PluginResponseMessage { MessageName = RegisterPluginMessageName }; var pluginId = message.PluginId; var registerDataTypeCacheKey = registerData.GetFullTypeCacheKey(); IPlugin plugin; Type pluginType; if (!_pluginTypeCache.TryGetValue(registerDataTypeCacheKey, out pluginType)) { try { Assembly assembly; if (!_assemblyCache.TryGetValue(registerData.AssemblyName, out assembly)) { assembly = assemblyLoadContext.Load(registerData.AssemblyName); } pluginType = assembly.GetType(registerData.TypeName); } catch (Exception exception) { response.Error = exception.Message; return response; } } if (pluginType == null) { response.Error = Resources.FormatPlugin_TypeCouldNotBeLocatedInAssembly( pluginId, registerData.TypeName, registerData.AssemblyName); return response; } else { // We build out a custom plugin service provider to add a PluginMessageBroker and // IAssemblyLoadContext to the potential services that can be used to construct an IPlugin. var pluginServiceProvider = new PluginServiceProvider( _hostServices, messageBroker: new PluginMessageBroker(pluginId, _sendMessageMethod)); plugin = ActivatorUtilities.CreateInstance(pluginServiceProvider, pluginType) as IPlugin; if (plugin == null) { response.Error = Resources.FormatPlugin_CannotProcessMessageInvalidPluginType( pluginId, pluginType.FullName, typeof(IPlugin).FullName); return response; } } Debug.Assert(plugin != null); _registeredPlugins[pluginId] = plugin; response.Success = true; return response; }
private PluginResponseMessage RegisterPlugin( PluginMessage message, IAssemblyLoadContext assemblyLoadContext) { var registerData = message.Data.ToObject <PluginRegisterData>(); var response = new PluginResponseMessage { MessageName = RegisterPluginMessageName }; var pluginId = message.PluginId; var registerDataTypeCacheKey = registerData.GetFullTypeCacheKey(); IPlugin plugin; Type pluginType; if (!_pluginTypeCache.TryGetValue(registerDataTypeCacheKey, out pluginType)) { try { Assembly assembly; if (!_assemblyCache.TryGetValue(registerData.AssemblyName, out assembly)) { assembly = assemblyLoadContext.Load(registerData.AssemblyName); } pluginType = assembly.GetType(registerData.TypeName); } catch (Exception exception) { response.Error = exception.Message; return(response); } } if (pluginType == null) { response.Error = Resources.FormatPlugin_TypeCouldNotBeLocatedInAssembly( pluginId, registerData.TypeName, registerData.AssemblyName); return(response); } else { // We build out a custom plugin service provider to add a PluginMessageBroker and // IAssemblyLoadContext to the potential services that can be used to construct an IPlugin. var pluginServiceProvider = new PluginServiceProvider( _hostServices, messageBroker: new PluginMessageBroker(pluginId, _sendMessageMethod)); plugin = ActivatorUtilities.CreateInstance(pluginServiceProvider, pluginType) as IPlugin; if (plugin == null) { response.Error = Resources.FormatPlugin_CannotProcessMessageInvalidPluginType( pluginId, pluginType.FullName, typeof(IPlugin).FullName); return(response); } } Debug.Assert(plugin != null); _registeredPlugins[pluginId] = plugin; response.Success = true; return(response); }
public Assembly Load(string name) { return(_context.Load(name)); }
public Assembly Load(AssemblyName assemblyName) { return(_assemblyLoadContext.Load(assemblyName)); }