c# - 为什么我在调用 ContextRegistry.GetContext() 时收到 Spring.NET 引发的异常?

标签 c# wpf 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 是我要实例化的类的完全限定名称。我猜是我弄错了,但看不出是怎么回事。

最佳答案

我觉得自己很傻。

这是因为我未能将 AlbumLibrary.dll 复制到正确的输出目录。这意味着 Spring 无法找到它 - 即使在我修复了 Kent 强调的程序集名称问题之后也是如此。

关于c# - 为什么我在调用 ContextRegistry.GetContext() 时收到 Spring.NET 引发的异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/765616/

相关文章:

c# - 框架升级到 3.5

c# - 在 Entity Framework 中使用 DbSet<TEntity>.Local 属性

c# - 为什么代码不会死锁

c# - spring.net有什么用?

.net - Spring.net WCF 服务和多线程 : manage count thread for exec WCF method

c# - 创建更像 Visual Studio 的 UI 框架

C# - 通过 Gmail 或其他方式发送电子邮件?

wpf - 将 wpf 图像控件保存到文件的最简单方法

wpf - 在事件 Keydown 中获取发件人文本框名称

c# - 我们可以创建发布事件的 WCF 服务吗?