MVC 4 MEF View从其他程序集中找不到@Model

问题描述:

我正在处理我的自定义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文件夹中的程序集。

如何配置我的系统以便视图可以从另一个文件夹搜索程序集?注意:程序集在运行时加载。

+0

我有同样的问题..你有没有找到任何解决方案? – marsop

而且您的文章是几月份的时候,我想下面的链接也许可以回答你的问题: http://shazwazza.com/post/Developing-a-plugin-framework-in-ASPNET-with-medium-trust

我希望这会帮助你。