我正在處理我的自定義CMS。我有主要的應用程序和模塊。我的問題是,每當我從我的模塊加載視圖,視圖無法找到分配給該視圖的模型。MVC 4 MEF View從其他程序集中找不到@Model
CS0246:類型或命名空間名稱「EAccounting」找不到(是否缺少using指令或程序集引用?)
該模塊的視圖位於〜/模塊/ EAccounting /瀏覽/。我可以調用模塊控制器沒有問題,我也可以找到調用從沒有問題的控制器的視圖,但視圖本身無法找到加載的組件模型:
@model EAccounting.Models.Transaction
這是代碼加載程序集:
public class SafeDirectoryCatalog : ComposablePartCatalog
{
private readonly AggregateCatalog _catalog;
public SafeDirectoryCatalog(string directory)
{
var files = Directory.EnumerateFiles(directory, "*.dll", SearchOption.AllDirectories);
_catalog = new AggregateCatalog();
foreach (var file in files)
{
try
{
var asmCat = new AssemblyCatalog(file);
//Force MEF to load the plugin and figure out if there are any exports
// good assemblies will not throw the RTLE exception and can be added to the catalog
if (asmCat.Parts.ToList().Count > 0)
{
_catalog.Catalogs.Add(asmCat);
}
}
catch (ReflectionTypeLoadException)
{
}
catch (BadImageFormatException)
{
}
}
}
public override IQueryable<ComposablePartDefinition> Parts
{
get { return _catalog.Parts; }
}
}
我敢肯定,程序集加載沒有問題。 另外,如果我將我的模塊組裝.dll移動到我的主bin文件夾(〜/ bin /),它工作正常,所以問題必須是該視圖只能搜索主/ bin文件夾中的程序集。
如何配置我的系統以便視圖可以從另一個文件夾搜索程序集?注意:程序集在運行時加載。
我有同樣的問題..你有沒有找到任何解決方案? – marsop