与出口问题不是特定类型的其他问题不同,这一问题是完全不同的。
类型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如何混淆这两种类型?
最佳答案
我现在重新测试了整个问题,一切正常。知道它是由两个独立的开发人员在两台计算机上复制的,所以我无法解释这种奇怪的行为...
关于c# - 导出“XYZ.IMessageCenterBL(ContractName =“XYZ.IMessageCenterBL”)”不可分配为类型“System.Web.Mvc.JsonResult”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31329914/