Пример #1
0
        private CidaModuleLoadContext InitializeLoadContext()
        {
            var context = new CidaModuleLoadContext();

            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);
        }
Пример #2
0
        public CidaModule(
            CidaModuleMetadata metadata,
            IDictionary <string, Stream> moduleFiles)
        {
            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);

            this.entryType = this.Assembly.GetType(this.Metadata.EntryType);
            if (this.entryType is null)
            {
                // TODO: Replace this with custom exception
                throw new InvalidOperationException($"Entry type '{this.Metadata.EntryType}' not found in assembly");
            }
        }