当我在ASP.NET MVC 3.0项目中引用Microsoft.Web.Mvc.dll时,出现错误,当我在构建DirecotryCatalog
我的CustomDependencyResolver
。ASP.NET MVC 3.0 + Microsoft.Web.Mvc 3.0 + MEF兼容性
string path = HostingEnvironment.MapPath("~/bin");
var container = new DirectoryCatalog(path);
然后我看着container.Parts.Results View.LoadedExeptions
和跟它:
+ [0] {“方法 'GetControllerSessionBehavior' 从组件类型 'Microsoft.Web.Mvc.MvcDynamicSessionControllerFactory'“Microsoft.Web .Mvc,版本= 3.0.0.0,文化=中立,公钥=空”没有实现。 “:” Microsoft.Web.Mvc.MvcDynamicSessionControllerFactory“} {System.Exception的} System.TypeLoadException
+ [1] {“组件'Microsoft.Web.Mvc,版本= 3.0.0.0,Culture = neutral,PublicKeyToken = null'类型为'Microsoft.Web.Mvc.Resources.ResourceControllerFactory'中的Method'GetControllerSessionBehavior'没有的实施方式。 “:” Microsoft.Web.Mvc.Resources.ResourceControllerFactory“} {的System.Exception} System.TypeLoadException
只是为了测试我删除参考Microsoft.Web.Mvc.dll(物理上除去它斌direcotry),然后一切都很好。看起来像Microsoft.Web.Mvc.dll无法加载。
有什么解决办法吗?
我在这里发现了类似的问题http://forums.asp.net/t/1622399.aspx?MVC+3+RC.+Where+is+the+Futures+Assembly%3F回答说MVC 3 Beta期货+ MVC 3 RC Runtime =是不兼容的。但我同时使用RTM版本:
Microsoft.Web.Mvc运行时版本v4.0.30319,版本3.0.0.0(从这里下载http://mvccontrib.codeplex.com/releases/view/59313)
System.Web.Mvc运行V4版本。 0.30319,版本3.0.0.0
更新:
正如达林·季米特洛夫在他的回答,我需要从扫描过程中排除System.Web.Mvc menthioned。 这里是怎样的方式来做到这一点:
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)
{
}
}
}
public override IQueryable<ComposablePartDefinition> Parts
{
get { return _catalog.Parts; }
}
}
你是对的,我需要排除这个组件 – Kuncevic 2011-02-27 05:11:33