Unity.ResolutionFailedException - 依赖关系解析失败

发布于 2024-09-17 11:55:15 字数 3154 浏览 3 评论 0原文

我有以下代码:

 public static IEngine CreateEngine()
    {
        UnityContainer container = Unity.LoadUnityContainer(DefaultStrategiesContainerName);
        IEnumerable<IStrategy> strategies = container.ResolveAll<IStrategy>();
        ITraderProvider provider = container.Resolve<ITraderProvider>();

        return new Engine(provider, new List<IStrategy>(strategies));
    }

和配置:

<unity>  <typeAliases>
<typeAlias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
<typeAlias alias="weakRef" type="Microsoft.Practices.Unity.ExternallyControlledLifetimeManager, Microsoft.Practices.Unity" />
<typeAlias alias="Strategy" type="ADTrader.Core.Contracts.IStrategy, ADTrader.Core" />
<typeAlias alias="Trader" type="ADTrader.Core.Contracts.ITraderProvider, ADTrader.Core" />  </typeAliases>  <containers>
<container name="strategies">
  <types>
    <type type="Strategy" mapTo="ADTrader.Strategies.ThreeTurningStrategy, ADTrader.Strategies" name="1" />
    <type type="Trader" mapTo="ADTrader.MbTradingProvider.MBTradingProvider, ADTrader.MbTradingProvider" />
  </types>
</container>  </containers></unity>

我收到以下异常:

Microsoft.Practices.Unity.ResolutionFailedException:解决 依赖失败,类型=“ADTrader.Core.Contracts.ITraderProvider”, 名称=“”。异常消息是:当前构建操作(构建 key 构建密钥[ADTrader.MbTradingProvider.MBTradingProvider, null]) 失败:尝试读取或写入受保护的内存。这通常是一个 表明其他内存已损坏。 (策略类型 BuildPlanStrategy,索引 3) ---> Microsoft.Practices.ObjectBuilder2.BuildFailedException:当前 构建操作(构建键Build Key[ADTrader.MbTradingProvider.MBTradingProvider, null]) 失败: 尝试读取或写入受保护的内存。这通常是一个 表明其他内存已损坏。 (策略类型 BuildPlanStrategy,索引 3) ---> System.AccessViolationException: 尝试读取或写入受保护的内存。这通常是一个 表明其他内存已损坏。在 MBTCOMLib.MbtComMgrClass.EnableSplash(布尔 bEnable) at ADTrader.MbTradingProvider.MBTradingProvider..ctor() 在 BuildUp_ADTrader.MbTradingProvider.MBTradingProvider(IBuilderContext ) 在 Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext 上下文)在 Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext 上下文)在 Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) --- 内部异常堆栈跟踪结束 --- at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext 上下文)在 Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator 定位器、ILifetimeContainer 生命周期、IPolicyList 策略、 IStrategyChain 策略、对象 buildKey、对象现有)位于 Microsoft.Practices.Unity.UnityContainer.DoBuildUp(类型 t,对象 现有的,字符串名称) --- 内部异常堆栈跟踪结束 ---
在 Microsoft.Practices.Unity.UnityContainer.DoBuildUp(类型 t,对象 现有,字符串名称)位于 Microsoft.Practices.Unity.UnityContainer.Resolve(类型 t,字符串名称) 在 Microsoft.Practices.Unity.UnityContainerBase.ResolveT 处 ADTrader.Engine.EngineFactory.CreateEngine()

有什么想法吗?

I have the following code:

 public static IEngine CreateEngine()
    {
        UnityContainer container = Unity.LoadUnityContainer(DefaultStrategiesContainerName);
        IEnumerable<IStrategy> strategies = container.ResolveAll<IStrategy>();
        ITraderProvider provider = container.Resolve<ITraderProvider>();

        return new Engine(provider, new List<IStrategy>(strategies));
    }

and the config:

<unity>  <typeAliases>
<typeAlias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
<typeAlias alias="weakRef" type="Microsoft.Practices.Unity.ExternallyControlledLifetimeManager, Microsoft.Practices.Unity" />
<typeAlias alias="Strategy" type="ADTrader.Core.Contracts.IStrategy, ADTrader.Core" />
<typeAlias alias="Trader" type="ADTrader.Core.Contracts.ITraderProvider, ADTrader.Core" />  </typeAliases>  <containers>
<container name="strategies">
  <types>
    <type type="Strategy" mapTo="ADTrader.Strategies.ThreeTurningStrategy, ADTrader.Strategies" name="1" />
    <type type="Trader" mapTo="ADTrader.MbTradingProvider.MBTradingProvider, ADTrader.MbTradingProvider" />
  </types>
</container>  </containers></unity>

I am getting the following exception:

Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the
dependency failed, type = "ADTrader.Core.Contracts.ITraderProvider",
name = "". Exception message is: The current build operation (build
key Build Key[ADTrader.MbTradingProvider.MBTradingProvider, null])
failed: Attempted to read or write protected memory. This is often an
indication that other memory is corrupt. (Strategy type
BuildPlanStrategy, index 3) --->
Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current
build operation (build key Build
Key[ADTrader.MbTradingProvider.MBTradingProvider, null]) failed:
Attempted to read or write protected memory. This is often an
indication that other memory is corrupt. (Strategy type
BuildPlanStrategy, index 3) ---> System.AccessViolationException:
Attempted to read or write protected memory. This is often an
indication that other memory is corrupt. at
MBTCOMLib.MbtComMgrClass.EnableSplash(Boolean bEnable) at
ADTrader.MbTradingProvider.MBTradingProvider..ctor() at
BuildUp_ADTrader.MbTradingProvider.MBTradingProvider(IBuilderContext )
at
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext
context) at
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext
context) at
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext
context) --- End of inner exception stack trace --- at
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext
context) at
Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator
locator, ILifetimeContainer lifetime, IPolicyList policies,
IStrategyChain strategies, Object buildKey, Object existing) at
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object
existing, String name) --- End of inner exception stack trace ---
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object
existing, String name) at
Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name)
at Microsoft.Practices.Unity.UnityContainerBase.ResolveT at
ADTrader.Engine.EngineFactory.CreateEngine()

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不是你的备胎 2024-09-24 11:55:15

MbTradingProvider.MBTradingProvider 的构造函数调用 COM 对象上的一个方法(从名称来看),MBTCOMLib.MbtComMgrClass.EnableSplash。这个方法有一个bug,会导致写入错误的内存地址。

The constructor of your MbTradingProvider.MBTradingProvider calls a method on a COM object (assuming from the name), MBTCOMLib.MbtComMgrClass.EnableSplash. This method has a bug in it, causing wrong memory address to be written.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文