【发布时间】:2016-08-19 07:33:04
【问题描述】:
我正在开发我的自定义 CMS。我有主要的应用程序和模块。我的问题是,每当我从模块加载视图时,视图都找不到分配给该视图的模型。
CS0246:找不到类型或命名空间名称“EAAccounting”(您是否缺少 using 指令或程序集引用?)
该模块的视图位于 ~/Modules/EAAccounting/Views/。我可以毫无问题地调用模块控制器,也可以毫无问题地从控制器中定位调用视图,但视图本身无法从加载的程序集中找到模型:
@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/) 中,它可以正常工作,所以问题一定是视图只能在 main/ 中搜索程序集bin 文件夹。
如何配置我的系统,以便视图可以从另一个文件夹中搜索程序集?注意:程序集在运行时加载。
【问题讨论】:
-
我也有同样的问题..你找到解决办法了吗?
标签: c# .net asp.net-mvc .net-assembly mef