2017-07-18 60 views
1

我正在創建一個網站,該網站應該能夠接受多個模塊並將這些模塊組合到主項目中。編程引導程序和自定義View引擎後,使其能夠在module.dll中查找視圖。System.IO.FileNotFoundException:無法加載文件或程序集'System.Web.DataVisualization MEF MVC

在編譯測試模塊進行測試之後,出現一個奇怪的錯誤,它說它由於某種原因無法加載System.Web.DataVisualization。我也注意到來自Module dll的控制器得到了正確的加載,我可以在調試中看到它,但是這個錯誤繼續查殺一個線程並拋出錯誤。

enter image description here

這是處理的DLL的加載/組成的代碼,我有Bootstrapper.cs。

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; 
    } 
} 

這是在測試時被拋出的錯誤。 enter image description here

回答

0

對此的解決方案是不幸的是手動下載DLL並將其添加到參考,但主要的修改是在處理web.config,我必須定義裝配進口System.Web.DataVisualization這樣。 <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

相關問題