与出口主题不属于某种类型的其他问题不同,这个问题完全不同。
类型XYZ.IMessageCenterBL
和System.Web.Mvc.JsonResult
完全不同 - 我们无法将它们混淆。
此外,如果我尝试使用System.Web.Mvc.JsonResult
而不是XYZ.IMessageCenterBL
,代码将无法编译。
现在XYZ.IMessageCenterBL
被注入一个属性:
[Import]
public IMessageCenterBL MessageCenterBL { get; set; }
请注意,没有任何混淆的地方 - 这个JsonResult
业务来自哪里?
此外,如果我将依赖项从属性移动到构造函数中(即IMessageCenterBL
被注入构造函数并且属性是从那里显式设置的)它开始工作!
以下是整个MEF异常输出:
Unhandled Exception at url: http://localhost:51000/u/2s4xYN1VikulrQAi44nvWg/Framework/XmlForm/GetTemplate
System.InvalidOperationException: An error occurred when trying to create a controller of type 'DF.Web.Framework.Controllers.XmlForms.XmlFormController`1[DF.Data.WorkFlow.WF_Employee]'. Make sure that the controller has a parameterless public constructor. ---> System.ComponentModel.Composition.CompositionException: The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) The export 'DF.Web.Framework.Business.IMessageCenterBL (ContractName="DF.Web.Framework.Business.IMessageCenterBL")' is not assignable to type 'System.Web.Mvc.JsonResult'.
Resulting in: Cannot set import 'DF.Web.Platform.DFController.Data (ContractName="DF.Web.Framework.Business.IMessageCenterBL")' on part 'DF.Web.Framework.Controllers.XmlForms.XmlFormController(DF.Data.WorkFlow.WF_Employee)'.
Element: DF.Web.Platform.DFController.Data (ContractName="DF.Web.Framework.Business.IMessageCenterBL") --> DF.Web.Framework.Controllers.XmlForms.XmlFormController({0}) --> AssemblyCatalog (Assembly="DF.Web.Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93")
Resulting in: Cannot get export 'DF.Web.Framework.Controllers.XmlForms.XmlFormController(DF.Data.WorkFlow.WF_Employee) (ContractName="DF.Web.Framework.Controllers.XmlForms.XmlFormController(DF.Data.WorkFlow.WF_Employee)")' from part 'DF.Web.Framework.Controllers.XmlForms.XmlFormController(DF.Data.WorkFlow.WF_Employee)'.
Element: DF.Web.Framework.Controllers.XmlForms.XmlFormController(DF.Data.WorkFlow.WF_Employee) (ContractName="DF.Web.Framework.Controllers.XmlForms.XmlFormController(DF.Data.WorkFlow.WF_Employee)") --> DF.Web.Framework.Controllers.XmlForms.XmlFormController({0}) --> AssemblyCatalog (Assembly="DF.Web.Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93")
at System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine engine, ComposablePart part, ExportDefinition definition)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedValue(CatalogPart part, ExportDefinition export, Boolean isSharedPart)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.CatalogExport.GetExportedValueCore()
at System.ComponentModel.Composition.Primitives.Export.get_Value()
at System.ComponentModel.Composition.ExportServices.GetCastedExportedValue[T](Export export)
at System.ComponentModel.Composition.ReflectionModel.ExportFactoryCreator.LifetimeContext.GetExportLifetimeContextFromExport[T](Export export)
at System.ComponentModel.Composition.ReflectionModel.ExportFactoryCreator.<>c__DisplayClass4`1.<CreateStronglyTypedExportFactoryOfT>b__3()
at System.ComponentModel.Composition.ExportFactory`1.CreateExport()
at DF.Web.Platform.MefDependencyResolver.CacheItem`1.GetService(CompositionContainer compositionContainer) in c:\DF\SharpTop\UI\Platform\MefDependencyResolver.cs:line 41
at DF.Web.Platform.MefDependencyResolver.System.Web.Mvc.IDependencyResolver.GetService(Type serviceType) in c:\DF\SharpTop\UI\Platform\MefDependencyResolver.cs:line 100
at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
--- End of inner exception stack trace ---
at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
MEF如何混淆这两种类型?
答案 0 :(得分:0)
我现在只是重新测试了整个问题,它运作正常。知道它是由两个独立的开发人员在两台计算机上复制的,我对这种奇怪的行为没有解释......