Mono上使用MEFContrib与MVC3时出错
问题描述:
管理得到Mono & Mod_Mono安装在我的Centos 5服务器上时,我设法让服务器激活我的MVC3站点(它在IIS下运行愉快)。Mono上使用MEFContrib与MVC3时出错
不幸的是,试图与Apache运行的时候,我得到了一个错误:
找不到方法: 'System.Web.Helpers.Chart.ExecuteChartAction'。 描述:HTTP 500.错误处理请求。
这是我特有的,因为我根本没有在Chart代码中引用Chart类。异常也似乎来自Composition,并且堆栈跟踪包括对MefContrib的各种引用。
我已经尝试过在我的bin目录中有各种不同的.dlls组合。这是一个让我到这个阶段它的当前内容:
MyDll.dll MefContrib.Web.Mvc.dll System.Web.WebPages.Deployment.dll
MyDll.pdb System.Web.Helpers.dll System.Web.WebPages.Deployment.xml
MyDll2.dll System.Web.Helpers.xml System.Web.WebPages.dll
MyDll2.pdb System.Web.Mvc.dll System.Web.WebPages.Razor.dll
HtmlAgilityPack.dll System.Web.Mvc.xml System.Web.WebPages.Razor.xml
HtmlAgilityPack.pdb System.Web.Razor.dll System.Web.WebPages.xml
HtmlAgilityPack.xml System.Web.Razor.xml WebActivator.dll
MefContrib.dll System.Web.Routing.dll
凡MYDLL & MyDll2是我所建的项目的DLL包括各种出口&进口服务,为MEF组成。
我最好的猜测是MefContrib dll中有些东西与Mono不能很好地配合,除此之外,我的项目是一个非常简单的MVC3应用程序。
完整的堆栈跟踪:在“/”应用
Method not found: 'System.Web.Helpers.Chart.ExecuteChartAction'.
Description: HTTP 500. Error processing request.
Stack Trace:
Server Error in '/' Application
Method not found: 'System.Web.Helpers.Chart.ExecuteChartAction'.
Description: HTTP 500. Error processing request.
Stack Trace:
System.MissingMethodException: Method not found: 'System.Web.Helpers.Chart.ExecuteChartAction'.
at (wrapper managed-to-native) System.Reflection.MonoMethodInfo.get_method_info (intptr,System.Reflection.MonoMethodInfo&) <IL 0x00008, 0x0004c>
at System.Reflection.MonoMethodInfo.GetMethodInfo (intptr) [0x00000] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/corlib/System.Reflection/MonoMethod.cs:63
at System.Reflection.MonoMethod.GetPseudoCustomAttributes() [0x00002] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/corlib/System.Reflection/MonoMethod.cs:295
at System.MonoCustomAttrs.GetPseudoCustomAttributes (System.Reflection.ICustomAttributeProvider,System.Type) [0x0000d] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/corlib/System/MonoCustomAttrs.cs:68
at System.MonoCustomAttrs.IsDefined (System.Reflection.ICustomAttributeProvider,System.Type,bool) [0x00039] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/corlib/System/MonoCustomAttrs.cs:291
at System.Reflection.MonoMethod.IsDefined (System.Type,bool) [0x00000] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/corlib/System.Reflection/MonoMethod.cs:276
at Microsoft.Internal.AttributeServices.IsAttributeDefined<System.ComponentModel.Composition.ExportAttribute> (System.Reflection.ICustomAttributeProvider,bool) <0x00036>
at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.IsExport (System.Reflection.ICustomAttributeProvider) [0x00000] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/AttributedModel/AttributedPartCreationInfo.cs:355
at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo/<GetExportMembers>c__Iterator0.MoveNext() [0x0017f] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/AttributedModel/AttributedPartCreationInfo.cs:302
at System.Linq.Enumerable.Any<System.Reflection.MemberInfo> (System.Collections.Generic.IEnumerable`1<System.Reflection.MemberInfo>) <0x0009e>
at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.HasExports() [0x00000] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/AttributedModel/AttributedPartCreationInfo.cs:106
at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.IsPartDiscoverable() [0x0003a] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/AttributedModel/AttributedPartCreationInfo.cs:95
at System.ComponentModel.Composition.AttributedModel.AttributedModelDiscovery.CreatePartDefinitionIfDiscoverable (System.Type,System.ComponentModel.Composition.Primitives.ICompositionElement) [0x0000a] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/AttributedModel/AttributedModelDiscovery.cs:19
at System.ComponentModel.Composition.Hosting.TypeCatalog.get_PartsInternal() [0x00051] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/TypeCatalog.cs:166
at System.ComponentModel.Composition.Hosting.TypeCatalog.get_Parts() [0x00006] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/TypeCatalog.cs:123
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_Parts() [0x00000] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/AssemblyCatalog.cs:137
at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,System.ComponentModel.Composition.Primitives.ComposablePartCatalog) <IL 0x00001, 0x00013>
at System.Linq.Enumerable/<CreateSelectManyIterator>c__Iterator29`2<System.ComponentModel.Composition.Primitives.ComposablePartCatalog, System.ComponentModel.Composition.Primitives.ComposablePartDefinition>.MoveNext() <0x00114>
at System.Linq.Enumerable/<CreateSelectManyIterator>c__Iterator29`2<System.ComponentModel.Composition.Primitives.ComposablePartCatalog, System.ComponentModel.Composition.Primitives.ComposablePartDefinition>.MoveNext() <0x00206>
at System.Collections.Generic.List`1<System.ComponentModel.Composition.Primitives.ComposablePartDefinition>.AddEnumerable (System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.ComposablePartDefinition>) <0x0008a>
at System.Collections.Generic.List`1<System.ComponentModel.Composition.Primitives.ComposablePartDefinition>..ctor (System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.ComposablePartDefinition>) <0x0008b>
at MefContrib.Hosting.Interception.InterceptingCatalog.GetParts() <IL 0x00033, 0x0009b>
at MefContrib.Hosting.Interception.InterceptingCatalog.get_Parts() <IL 0x00001, 0x0000f>
at System.ComponentModel.Composition.Primitives.ComposablePartCatalog.GetExports (System.ComponentModel.Composition.Primitives.ImportDefinition) [0x00017] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Primitives/ComposablePartCatalog.cs:88
at MefContrib.Hosting.Interception.InterceptingCatalog.GetExports (System.ComponentModel.Composition.Primitives.ImportDefinition) <IL 0x00010, 0x00033>
at MefContrib.Hosting.Filter.FilteringCatalog.GetExports (System.ComponentModel.Composition.Primitives.ImportDefinition) <IL 0x00007, 0x00021>
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition) [0x00040] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/CatalogExportProvider.cs:279
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition,System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.Export>&) [0x00006] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/ExportProvider.cs:208
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition) [0x0000b] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/ExportProvider.cs:102
at System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition) [0x00030] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/AggregateExportProvider.cs:157
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition,System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.Export>&) [0x00006] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/ExportProvider.cs:208
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition,System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.Export>&) [0x0000e] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/ExportProvider.cs:145
at System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition) [0x00008] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/CompositionContainer.cs:396
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition,System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.Export>&) [0x00006] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/ExportProvider.cs:208
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition) [0x0000b] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/ExportProvider.cs:102
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportsCore (System.Type,System.Type,string,System.ComponentModel.Composition.Primitives.ImportCardinality) [0x0006b] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/ExportProvider.GetExportOverrides.cs:799
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports (System.Type,System.Type,string) [0x00000] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.ComponentModel.Composition/src/ComponentModel/System/ComponentModel/Composition/Hosting/ExportProvider.GetExportOverrides.cs:267
at MefContrib.Web.Mvc.CompositionDependencyResolver.GetService (System.Type) <IL 0x00009, 0x0002b>
at System.Web.Mvc.DependencyResolverExtensions.GetService<System.Web.Mvc.IControllerFactory> (System.Web.Mvc.IDependencyResolver) <0x0002d>
at System.Web.Mvc.SingleServiceResolver`1<System.Web.Mvc.IControllerFactory>.get_Current() <0x00097>
at System.Web.Mvc.ControllerBuilder.GetControllerFactory() <IL 0x00006, 0x00021>
at System.Web.Mvc.MvcRouteHandler.GetSessionStateBehavior (System.Web.Routing.RequestContext) <IL 0x00024, 0x00097>
at System.Web.Mvc.MvcRouteHandler.GetHttpHandler (System.Web.Routing.RequestContext) <IL 0x00008, 0x0002c>
at System.Web.Mvc.MvcRouteHandler.System.Web.Routing.IRouteHandler.GetHttpHandler (System.Web.Routing.RequestContext) <IL 0x00002, 0x00015>
at System.Web.Routing.UrlRoutingModule.PostResolveRequestCache (System.Web.HttpContextBase) [0x00054] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.Web.Routing/System.Web.Routing/UrlRoutingModule.cs:127
at System.Web.Routing.UrlRoutingModule.PostResolveRequestCache (object,System.EventArgs) [0x00007] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.Web.Routing/System.Web.Routing/UrlRoutingModule.cs:87
at System.Web.HttpApplication/<RunHooks>c__Iterator5.MoveNext() [0x001aa] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.Web/System.Web/HttpApplication.cs:1050
at System.Web.HttpApplication/<Pipeline>c__Iterator6.MoveNext() [0x006d3] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.Web/System.Web/HttpApplication.cs:1259
at System.Web.HttpApplication.Tick() [0x00000] in /usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System.Web/System.Web/HttpApplication.cs:932
Version information: Mono Runtime Version: 2.10.2 (tarball Mon Apr 18 19:06:50 UTC 2011); ASP.NET Version: 4.0.30319.1
答
服务器错误此等问题使我回答这个问题: missingmethodexception-w-mono
事实证明,MefContrib设置默认情况下使用DirectoryCatalog,这对Mono来说不起作用(因为它试图在没有任何东西的dll中找到Exports - 在Windows中很好)。
如果您将您的应用程序的Start()方法中的MvcApplicationRegistry替换为您自己的自定义应用程序,它只是查看您的dll(并且不扫描整个bin),那么一切都很开心。
Start()方法:
var catalog = new AggregateCatalog(
new AssemblyCatalog(Assembly.GetAssembly(typeof(MyClass))),
new ConventionCatalog(new MyMvcApplicationRegistry()));
MvcApplicationRegistry:
public class MyMvcApplicationRegistry : PartRegistry
{
public MyMvcApplicationRegistry()
{
Scan(x => x.Assembly(Assembly.GetExecutingAssembly()));
Part()
.ForTypesAssignableFrom<IController>()
.MakeNonShared()
.AddMetadata(new PartCreationScopeAttribute(PartCreationScope.Default))
.ExportAs<IController>()
.Export()
.Imports(x =>
{
x.Import().Members(
m => new[] { m.GetConstructors().FirstOrDefault(c => c.GetCustomAttributes(typeof(ImportingConstructorAttribute), false).Length > 0) ?? m.GetGreediestConstructor() });
x.Import().Members(
m => m.GetMembers().Where(mbr => mbr.GetCustomAttributes(typeof(ImportAttribute), false).Length > 0).ToArray());
});
}
}