I am creating a website which should be able to take in multiple modules and compose those modules to a main project. After programming the bootstrapper and custom View engine to make it able to find Views in the module.dll.
After compiling a test module for testing, I am getting a weird error where it says it cannot load System.Web.DataVisualization for some reason. I have also noticed that the Controller from the Module dll gets loaded properly, I can see it in the debug but this error keeps killing a thread and throws the error.
This is the code I have for Bootstrapper.cs that handles the loading/composing of the dlls.
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.IO;
public class Bootstrapper
{
private static CompositionContainer CompositionContainer;
private static bool IsLoaded = false;
public static void Compose(List<string> pluginFolders)
{
if (IsLoaded) return;
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin")));
foreach (var plugin in pluginFolders)
{
var directoryCatalog = new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", plugin));
catalog.Catalogs.Add(directoryCatalog);
}
CompositionContainer = new CompositionContainer(catalog);
CompositionContainer.ComposeParts();
IsLoaded = true;
}
public static T GetInstance<T>(string contractName = null)
{
var type = default(T);
if (CompositionContainer == null) return type;
if (!string.IsNullOrWhiteSpace(contractName))
type = CompositionContainer.GetExportedValue<T>(contractName);
else
type = CompositionContainer.GetExportedValue<T>();
return type;
}
}
The solution for this was to unfortunately manually download the dll and add it to the reference, but the main edit was to Web.Config where I had to define the assembly to import System.Web.DataVisualization
as such. <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />