gpt4 book ai didi

c# - export 'XYZ.IMessageCenterBL (ContractName="XYZ.IMessageCenterBL")' is not assignable to type ' System.Web.Mvc.JsonResult'

转载 作者:行者123 更新时间:2023-11-30 18:24:23 25 4
gpt4 key购买 nike

与关于导出主题的其他问题不同,这个问题完全不同。

XYZ.IMessageCenterBLSystem.Web.Mvc.JsonResult 类型完全不同 - 我们无法混淆它们。

此外,如果我尝试使用 System.Web.Mvc.JsonResult 而不是 XYZ.IMessageCenterBL,代码将无法编译。

现在 XYZ.IMessageCenterBL 被注入(inject)到一个属性中:

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

请注意,这里没有任何混淆的地方 - 这个 JsonResult 业务来自哪里?

此外,如果我将依赖项从属性移到构造函数中(即 IMessageCenterBL 被注入(inject)到构造函数中并从那里显式设置属性),它就会开始工作!

这里是整个 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# - export 'XYZ.IMessageCenterBL (ContractName="XYZ.IMessageCenterBL")' is not assignable to type ' System.Web.Mvc.JsonResult',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31329914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com