protected virtual ValueOrProceed <AssemblyFromStrategy> LoadFromDefaultContext(IPluginLoadContext pluginLoadContext, AssemblyName assemblyName) { try { var assembly = Default.LoadFromAssemblyName(assemblyName); if (assembly != null) { return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.NotReleasable(assembly), false)); } } catch (FileNotFoundException) { } // This can happen if the plugin uses a newer version of a package referenced in the host var hostAssembly = this.pluginDependencyContext.HostDependencies.FirstOrDefault(h => h.DependencyName.Name == assemblyName.Name); if (hostAssembly != null && !hostAssembly.AllowDowngrade) { if (!!hostAssembly.AllowDowngrade) { throw new PrisePluginException($"Plugin<{typeof(T)}> Assembly reference {assemblyName.Name} with version {assemblyName.Version} was requested but not found in the host. The version from the host is {hostAssembly.DependencyName.Version}. Possible version mismatch. Please downgrade your plugin."); } this.logger.VersionMismatch(assemblyName, hostAssembly.DependencyName); } return(ValueOrProceed <AssemblyFromStrategy> .Proceed()); }
protected Assembly LoadAndAddToWeakReferences(AssemblyFromStrategy assemblyFromStrategy) { if (assemblyFromStrategy != null && assemblyFromStrategy.CanBeReleased) { this.assemblyReferences.Add(new System.WeakReference(assemblyFromStrategy.Assembly)); } return(assemblyFromStrategy?.Assembly); }
/// <summary> /// This override includes the netcore 3.0 resolver /// </summary> /// <param name="assemblyName"></param> /// <returns></returns> protected override ValueOrProceed <AssemblyFromStrategy> LoadFromDependencyContext(IPluginLoadContext pluginLoadContext, AssemblyName assemblyName) { var assemblyPath = resolver.ResolveAssemblyToPath(assemblyName); if (!String.IsNullOrEmpty(assemblyPath) && File.Exists(assemblyPath)) { return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(LoadFromAssemblyPath(assemblyPath)), false)); } return(base.LoadFromDependencyContext(pluginLoadContext, assemblyName)); }
protected virtual ValueOrProceed <AssemblyFromStrategy> LoadDependencyFromLocalDisk(IPluginLoadContext pluginLoadContext, string assemblyFileName) { var dependency = LoadFileFromLocalDisk(pluginLoadContext.PluginAssemblyPath, assemblyFileName); if (dependency == null) { return(ValueOrProceed <AssemblyFromStrategy> .Proceed()); } return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(Assembly.Load(ToByteArray(dependency))), false)); }
protected override ValueOrProceed <AssemblyFromStrategy> LoadFromRemote(IPluginLoadContext pluginLoadContext, AssemblyName assemblyName) { var networkAssembly = LoadDependencyFromNetwork(assemblyName); if (networkAssembly != null) { return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(networkAssembly), false)); } return(ValueOrProceed <AssemblyFromStrategy> .Proceed()); }
protected virtual ValueOrProceed <AssemblyFromStrategy> LoadFromDependencyContext(IPluginLoadContext pluginLoadContext, AssemblyName assemblyName) { if (IsResourceAssembly(assemblyName)) { foreach (var resourceDependency in this.pluginDependencyContext.PluginResourceDependencies) { var resourcePath = Path.Combine(resourceDependency.Path, assemblyName.CultureName, assemblyName.Name + ".dll"); if (File.Exists(resourcePath)) { return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(LoadFromAssemblyPath(resourcePath)), false)); } } // Do not proceed probing return(ValueOrProceed <AssemblyFromStrategy> .FromValue(null, false)); } var pluginDependency = this.pluginDependencyContext.PluginDependencies.FirstOrDefault(d => d.DependencyNameWithoutExtension == assemblyName.Name); if (pluginDependency != null) { var dependencyPath = this.dependencyPathProvider.GetDependencyPath(); if (String.IsNullOrEmpty(dependencyPath)) { dependencyPath = pluginLoadContext.PluginAssemblyPath; } var probingPaths = this.probingPathsProvider.GetProbingPaths(); var dependency = this.pluginDependencyResolver.ResolvePluginDependencyToPath(dependencyPath, probingPaths, pluginDependency); if (dependency != null) { return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(LoadFromStream(dependency)), false)); } } var localFile = Path.Combine(this.dependencyPathProvider.GetDependencyPath(), assemblyName.Name + ".dll"); if (File.Exists(localFile)) { return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(LoadFromAssemblyPath(localFile)), false)); } return(ValueOrProceed <AssemblyFromStrategy> .Proceed()); }
protected override ValueOrProceed <AssemblyFromStrategy> LoadFromDependencyContext(IPluginLoadContext pluginLoadContext, AssemblyName assemblyName) { if (IsResourceAssembly(assemblyName)) { foreach (var resourceDependency in this.pluginDependencyContext.PluginResourceDependencies) { var resourceNetworkPathToAssembly = Path.Combine(this.baseUrl, Path.Combine(resourceDependency.Path, assemblyName.CultureName, $"{assemblyName.Name}.dll")); var resourceNetworkAssembly = LoadDependencyFromNetwork(resourceNetworkPathToAssembly); if (resourceNetworkAssembly != null) { return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(resourceNetworkAssembly), false)); } } // Do not proceed probing return(ValueOrProceed <AssemblyFromStrategy> .FromValue(null, false)); } var pluginDependency = this.pluginDependencyContext.PluginDependencies.FirstOrDefault(d => d.DependencyNameWithoutExtension == assemblyName.Name); if (pluginDependency != null) { var dependencyPath = this.dependencyPathProvider.GetDependencyPath(); var probingPaths = this.probingPathsProvider.GetProbingPaths(); var resolvedNetworkAssembly = this.pluginDependencyResolver.ResolvePluginDependencyToPath(dependencyPath, probingPaths, pluginDependency); if (resolvedNetworkAssembly != null) { return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(LoadFromStream(resolvedNetworkAssembly)), false)); } } var networkPathToAssembly = $"{baseUrl}/{Path.Combine(this.dependencyPathProvider.GetDependencyPath(), assemblyName.Name)}.dll"; var networkAssembly = LoadDependencyFromNetwork(networkPathToAssembly); if (networkAssembly != null) { return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(networkAssembly), false)); } return(ValueOrProceed <AssemblyFromStrategy> .Proceed()); }