Why am I getting an exception raised from Spring.NET when I call ContextRegistry.GetContext ()?

Although the solution is so obvious that I would never have published it, I leave it as a reminder and a useful link to others.

In my app.config file there is the following:

<sectionGroup name="spring">
  <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
  <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>

The following are:

<spring>
  <context>
    <resource uri="config://spring/objects"/>
  </context>
  <objects xmlns="http://www.springframework.net">
    <object name="mediaLibrary" type="AlbumLibraryWPF.AlbumLibrary, AlbumLibraryWPF"/>
  </objects>
</spring>

Then in my application, I have:

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
}

All this compiles fine, however I get an exception that occurred when calling GetContext ():

Error creating context 'spring.root': Could not load type from string value
'AlbumLibraryWPF.AlbumLibrary, AlbumLibraryWPF'.

I checked the Spring.NET documentation and can't see what I'm doing wrong, but I obviously have something wrong, otherwise it would not throw an exception!

AlbumLibraryWPFis the namespace, and AlbumLibraryWPF.AlbumLibraryis the fully qualified name of the class I want to create. I assume that this did not work out for me, but I don’t see how to do it.

+3
6

.

, AlbumLibrary.dll . , Spring - , , Kent.

+4

, .

+1

name :

<object id="mediaLibrary" type="AlbumLibraryWPF.AlbumLibrary, AlbumLibraryWPF"/>

config://spring/objects config://spring/obects.

, AlbumLibrary AlbumLibraryWPF , AlbumLibraryWPF.

0

, app.config [! * 2]. , . -

<context>
  <!--<resource uri="~//Aspects.xml"/>-->
  <!--<resource uri="~//Dao.xml"/>-->
  <!--<resource uri="~//Spring.xml"/>-->
  <resource uri="file://Spring.xml"/>
  <resource uri="file://Dao.xml"/>
</context>

! * 2

0

You can try changing the type. Type = "AlbumLibraryWPF.AlbumLibrary, AlbumLibraryWPF", the first parameter means NameSpace, and the second parameter (behind the dot) means the name of the solution.

  • "AlbumLibraryWPF.AlbumLibrary" = NameSapce name
  • "AlbumLibraryWPF" = solution name
-1
source
  • Open VS2012 or VS2010 with administrator privileges.
  • Config: type = "namespace.type, assembly"

Then try running the solution again.

-1
source

Source: https://habr.com/ru/post/1706674/


All Articles