ContextRegistry rootContextName 始终为 null 或为空
使用 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 为 null - 公平调用,解释了我认为的异常。
还请注意,代码在调试期间可以正常运行,但一旦在调试之外运行就会失败。在安装过程中检查的 dll、依赖项和配置都位于正确的位置。
“强制输入”GetContext();
上下文名称,“spring.root”按照调试会话 rootContextName
值,并且异常消失,但 IApplicationContext 返回 null。
这里有什么想法或明显的问题吗?
Using Spring.NET IoC to inject dependency objects into properties. The app is an Outlook plug-in.
The code:
IApplicationContext ctx = ContextRegistry.GetContext();
this.Property = (MyObject)ctx.GetObject("MyObject");
The Config:
<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 -->
This code was running fine for around 2 years and then we upgraded a few assemblies around Outlook to run in Outlook 2010 and some Ribbon modifications - nothing that should affect Spring.NET I think.
Started getting the "The context name passed to the GetContext method cannot be null or empty" exception thrown on the GetContext();
call. On closer inspection I noted that the rootContextName
is null - fair call, explains the exception I thought.
Also noted that the code would run fine during debug but fail once it runs outside debug. Checked dll's, dependencies and configs are all in the right place during install.
"Force fed" GetContext();
a context name, "spring.root" as per debug session rootContextName
value, and the exception goes away but IApplicationContext
is returned null.
Any ideas or obvious issues here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论