private static IRhetosRuntime CreateRhetosRuntimeInstance(ILogProvider logProvider, string rhetosRuntimePath) { var assemblyResolver = AssemblyResolver.GetResolveEventHandler(new[] { rhetosRuntimePath }, logProvider, true); AppDomain.CurrentDomain.AssemblyResolve += assemblyResolver; try { var pluginScanner = new PluginScanner(new[] { rhetosRuntimePath }, Path.GetDirectoryName(rhetosRuntimePath), logProvider, new PluginScannerOptions()); var rhetosRuntimeTypes = pluginScanner.FindPlugins(typeof(IRhetosRuntime)).Select(x => x.Type).ToList(); if (rhetosRuntimeTypes.Count == 0) { throw new FrameworkException($"No implementation of interface {nameof(IRhetosRuntime)} found with Export attribute."); } if (rhetosRuntimeTypes.Count > 1) { throw new FrameworkException($"Found multiple implementation of the type {nameof(IRhetosRuntime)}."); } var rhetosRuntimeInstance = (IRhetosRuntime)Activator.CreateInstance(rhetosRuntimeTypes.Single()); return(rhetosRuntimeInstance); } finally { AppDomain.CurrentDomain.AssemblyResolve -= assemblyResolver; } }
public void AnalyzeAndReportTypeLoadException() { var incompatibleAssemblies = new[] { GetIncompatibleAssemblyPath() }; var pluginsScanner = new PluginScanner(incompatibleAssemblies, ".", new ConsoleLogProvider(), new PluginScannerOptions()); TestUtility.ShouldFail <FrameworkException>( () => pluginsScanner.FindPlugins(typeof(IGenerator)), "Please check if the assembly is missing or has a different version.", "'Rhetos.RestGenerator.dll' throws FileNotFoundException: Could not load file or assembly 'Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The system cannot find the file specified."); }
public void AnalyzeAndReportTypeLoadException() { // The "TestReference" project is used because it has dependencies to libraries that are not available in the current project. string incompatibleAssemblyPath = FindIncompatibleAssemblyPath("Rhetos.Extensibility.TestReference"); // Copying the "TestReference" assembly to local folder, to avoid automatic detection of dependency libraries that exist in its original location. // The goal is to try loading the test assembly without dependencies available. CopyAssemblyToLocalFolder(ref incompatibleAssemblyPath); // Searching for plugins in the "TestReference" assembly should fail because is references dependency that is not available. var pluginsScanner = new PluginScanner(new[] { incompatibleAssemblyPath }, new RhetosBuildEnvironment { CacheFolder = "." }, new ConsoleLogProvider(), new PluginScannerOptions()); TestUtility.ShouldFail <FrameworkException>( () => pluginsScanner.FindPlugins(typeof(ICloneable)), "Please check if the assembly is missing or has a different version.", // The error shout report: (1) the assembly that causes the error, and (2) the missing assembly that is required for the first one to load. "'Rhetos.Extensibility.TestReference.dll' throws FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Primitives, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified."); }