2011-12-19 63 views
0

管理得到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 

回答

2

服務器錯誤此等問題使我回答這個問題: 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()); 
       }); 
     } 
     }