public void LoadNodeFromName(AssemblyDependencyNode node) { if (node.Name == null) { throw new InvalidOperationException("Cannot load assembly from name, the name is empty."); } switch (node.LoadedFromName) { case AssemblyLoadStatus.Loaded: throw new InvalidOperationException("Cannot load assembly from name, it's already loaded."); case AssemblyLoadStatus.Failed: throw new InvalidOperationException("Cannot load assembly from name, previous attempt failed."); } if (node.Loaded) { throw new InvalidOperationException("Cannot load assembly from name, it's already been loaded."); } var assemblyString = node.Name.ToString(); try { Logger.Debug("Loading from name {AssemblyName}.", assemblyString); var assembly = AssemblyMetadataLoader.Load(node.Name); if (assembly.AssemblyName != node.Name.FullName) { Logger.Warning("Requesting the load of [{RequestedAssemblyName}], but obtained [{LoadedAssemblyName}].", node.Name.FullName, assembly.AssemblyName); } node.MarkAsLoadedFromName(assembly); ProcessLoadedNode(node); } catch (Exception ex) { Logger.Debug(ex, "Failed to load from name {AssemblyName}.", assemblyString); node.MarkAsFailedFromName(ex); } }
public void LoadNodeFromFile(AssemblyDependencyNode node) { if (node.File == null) { throw new InvalidOperationException("Cannot load assembly from file, the file is empty."); } switch (node.LoadedFromFile) { case AssemblyLoadStatus.Loaded: throw new InvalidOperationException("Cannot load assembly from file, it's already loaded."); case AssemblyLoadStatus.Failed: throw new InvalidOperationException("Cannot load assembly from file, previous attempt failed."); } if (node.Loaded) { throw new InvalidOperationException("Cannot load assembly from file, it's already been loaded."); } var fileFullName = node.File.FullName; try { Logger.Debug("Loading from file {File}.", fileFullName); var assembly = AssemblyMetadataLoader.LoadFrom(fileFullName); node.MarkAsLoadedFromFile(assembly); ProcessLoadedNode(node); } catch (Exception ex) { Logger.Debug(ex, "Failed to load from file {File}.", fileFullName); node.MarkAsFailedFromFile(ex); } }