ContextRegistry rootContextName始终为null或空

时间:2011-11-10 00:02:04

标签: c# .net spring.net

使用Spring.NET IoC将依赖项对象注入属性。该应用是一个Outlook插件。

代码:

IApplicationContext ctx = ContextRegistry.GetContext();
this.Property = (MyObject)ctx.GetObject("MyObject");

配置:

<configuration>
  <configSections>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
    </sectionGroup>
  </configSections>
  <spring>
    <context>
      <resource uri="config://spring/objects"/>
    </context>
    <objects xmlns="http://www.springframework.net">
      <description></description>
      <!--Business Logic Layer Binding Objects-->
      <object name="MyObject" 
              type="Quadrant2.MSCRM.Recruit.OfficeAddins.Toolbar.BusinessLogic.Q2_Win_SearchClient_Logic, Quadrant2.MSCRM.Recruit.OfficeAddins.Toolbar.BusinessLogic">
        <property name="SearchClientDAL" ref="DAL_SearchClient"/>
      </object>
<!-- snip -->

此代码运行良好约2年,然后我们升级了一些围绕Outlook的程序集以在Outlook 2010中运行以及一些功能区修改 - 我认为没有任何影响Spring.NET的内容。

开始在GetContext();调用中抛出“传递给GetContext方法的上下文名称不能为null或为空”异常。仔细观察后,我注意到rootContextName是空的 - 公平的电话,解释了我认为的例外。

还要注意,代码在调试期间运行正常但在调试之外运行时失败。在安装过程中,已检查的dll,依赖项和配置都在正确的位置。

“强制馈送”GetContext();一个上下文名称,“spring.root”根据调试会话rootContextName值,异常消失,但IApplicationContext返回null。

这里有任何想法或明显的问题吗?

0 个答案:

没有答案
相关问题