Export "XYZ.IMessageCenterBL (ContractName =" XYZ.IMessageCenterBL ") cannot be assigned to type" System.Web.Mvc.JsonResult "

Unlike other non-type export questions, this is completely different.

Types XYZ.IMessageCenterBL

and System.Web.Mvc.JsonResult

completely and totally different - they can not be confused.

Also, the code won't compile if I try to use System.Web.Mvc.JsonResult

instead XYZ.IMessageCenterBL

.

Right now XYZ.IMessageCenterBL

injected into the property:

[Import]
public IMessageCenterBL MessageCenterBL { get; set; }

      

Notice how there is no room for confusion - where does this business come from JsonResult

?

Also, if I move the dependency on the property to the constructor (i.e. IMessageCenterBL

put into the constructor and the property is explicitly set there) it starts working!

Here is the entire output of the MEF exception:

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)

      

How can MEF mix these two types?

+3


source to share


1 answer


I just revisited the whole problem now and it works fine. Knowing that this was reproduced on two computers by two independent developers, I have no explanation for this strange behavior ...



0


source







All Articles