public AvaloniaModule( AvaloniaModuleMetadata metadata, IDictionary <string, Stream> moduleFiles) { Type entryType = null; this.Metadata = metadata; this.moduleFiles = moduleFiles; this.loadContext = this.InitializeLoadContext(); if (!this.moduleFiles.TryGetValue(this.Metadata.AssemblyFile, out var assembly)) { // TODO: Replace this with custom exception throw new InvalidOperationException($"Assembly '{this.Metadata.AssemblyFile}' not found!"); } this.Assembly = this.loadContext.LoadFromStream(assembly); // Hack: Don't use static ViewLocator.Assemblies.Add(this.Assembly); entryType = this.Assembly.GetType(this.Metadata.EntryType); if (entryType is null) { // TODO: Replace this with custom exception throw new InvalidOperationException($"Entry type '{this.Metadata.EntryType}' not found in assembly"); } this.Module = (IModule)Activator.CreateInstance(entryType); }
private CidaAvaloniaModuleLoadContext InitializeLoadContext() { var context = new CidaAvaloniaModuleLoadContext(); context.Resolving += (resolveContext, name) => { if (!this.moduleFiles.TryGetValue($"{name.Name}.dll", out var resolvedDependency)) { // TODO: Replace this with custom exception throw new InvalidOperationException($"Assembly '{name.Name}.dll' not found."); } return(resolveContext.LoadFromStream(resolvedDependency)); }; return(context); }