protected virtual ValueOrProceed <AssemblyFromStrategy> LoadFromRemote(string initialPluginLoadDirectory, AssemblyName assemblyName) { var assemblyFileName = $"{assemblyName.Name}.dll"; if (this.fileSystemUtilities.DoesFileExist(Path.Combine(initialPluginLoadDirectory, assemblyFileName))) { return(LoadDependencyFromLocalDisk(initialPluginLoadDirectory, assemblyFileName)); } return(ValueOrProceed <AssemblyFromStrategy> .Proceed()); }
protected virtual ValueOrProceed <IntPtr> LoadUnmanagedFromDefault(string initialPluginLoadDirectory, string unmanagedDllName) { var resolution = base.LoadUnmanagedDll(unmanagedDllName); if (resolution == default(IntPtr)) { return(ValueOrProceed <IntPtr> .Proceed()); } return(ValueOrProceed <IntPtr> .FromValue(resolution, false)); }
protected virtual ValueOrProceed <AssemblyFromStrategy> LoadDependencyFromLocalDisk(string directory, string assemblyFileName) { var dependency = this.fileSystemUtilities.ReadDependencyFileFromDisk(directory, assemblyFileName); if (dependency == null) { return(ValueOrProceed <AssemblyFromStrategy> .Proceed()); } return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(Assembly.Load(this.fileSystemUtilities.ToByteArray(dependency))), false)); }
// <summary> /// This override includes the netcore 3.0 resolver /// </summary> /// <param name="assemblyName"></param> /// <returns></returns> protected ValueOrProceed <AssemblyFromStrategy> LoadFromDependencyContext(string initialPluginLoadDirectory, AssemblyName assemblyName) { var assemblyPath = this.resolver.ResolveAssemblyToPath(assemblyName); if (!String.IsNullOrEmpty(assemblyPath) && this.fileSystemUtilities.DoesFileExist(assemblyPath)) { return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(LoadFromAssemblyPath(assemblyPath)), false)); } if (IsResourceAssembly(assemblyName)) { foreach (var resourceDependency in this.pluginDependencyContext.PluginResourceDependencies) { var resourcePath = Path.Combine(resourceDependency.Path, assemblyName.CultureName, assemblyName.Name + ".dll"); if (this.fileSystemUtilities.DoesFileExist(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 dependency = this.pluginDependencyResolver.ResolvePluginDependencyToPath(initialPluginLoadDirectory, pluginDependency, this.pluginDependencyContext.AdditionalProbingPaths); if (dependency != null) { return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(LoadFromStream(dependency)), false)); } } var localFile = Path.Combine(initialPluginLoadDirectory, assemblyName.Name + ".dll"); if (this.fileSystemUtilities.DoesFileExist(localFile)) { return(ValueOrProceed <AssemblyFromStrategy> .FromValue(AssemblyFromStrategy.Releasable(LoadFromAssemblyPath(localFile)), false)); } return(ValueOrProceed <AssemblyFromStrategy> .Proceed()); }
protected virtual ValueOrProceed <RuntimeAssemblyShim> LoadFromDefaultContext(string initialPluginLoadDirectory, AssemblyName assemblyName) { try { var assemblyShim = this.runtimeDefaultAssemblyLoadContext.LoadFromDefaultContext(assemblyName); if (assemblyShim != null) { return(ValueOrProceed <RuntimeAssemblyShim> .FromValue(assemblyShim, 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 AssemblyLoadingException($"Plugin 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 or add {assemblyName.Name} to downgradableHostAssemblies."); } } return(ValueOrProceed <RuntimeAssemblyShim> .Proceed()); }