即使解决方案如此明显,我应该从未发布过这个消息,我将它作为提醒和对其他人的参考。为什么我会在调用ContextRegistry.GetContext()时从Spring.NET中引发异常?
我有我的app.config文件如下:
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
其次:
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects xmlns="http://www.springframework.net">
<object name="mediaLibrary" type="AlbumLibraryWPF.AlbumLibrary, AlbumLibraryWPF"/>
</objects>
</spring>
然后在我的应用我有:
using Spring.Context;
using Spring.Context.Support;
public partial class AlbumChecker : Window
{
private DataTable dataTable;
private Library library;
private Thread libraryThread;
public AlbumChecker()
{
InitializeComponent();
CreateToolTips();
IApplicationContext ctx = ContextRegistry.GetContext();
library = (Library)ctx.GetObject("mediaLibrary");
// Other initialisation
}
// Other code
}
这一切都编译得非常好,但是,我得到了一个GetContext()调用中引发的异常:
Error creating context 'spring.root': Could not load type from string value
'AlbumLibraryWPF.AlbumLibrary, AlbumLibraryWPF'.
我检查了Spring.NET的文档,看不到我在做什么错 - 但我明显有错误,否则它不会引发异常!
AlbumLibraryWPF
是命名空间,AlbumLibraryWPF.AlbumLibrary
是我想要实例化的类的全限定名。我猜测这是我错了,但看不到。
我有这个完全相同的问题,因为我的项目输出指向不同的位置。更改项目以将dll输出到相同的目录为我修复了一切 – lomaxx 2009-04-29 05:09:38