4

Even though the solution is so obvious I should have never have posted this, I'm leaving it up as a reminder and a useful point of reference to others.

I've got the following in my app.config file:

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

Followed by:

<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 app I've got:

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
}

It all compiles quite nicely, however, I'm getting an exception raised on the call to GetContext():

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

I've checked the Spring.NET documentation and can't see what I'm doing wrong - but I clearly have got something wrong, otherwise it wouldn't raise the exception!

AlbumLibraryWPF is the namespace and AlbumLibraryWPF.AlbumLibrary is the fully qualified name of the class I want to instantiate. I'm guessing that it's this I've got wrong, but can't see how.

Marijn
  • 10,367
  • 5
  • 59
  • 80
ChrisF
  • 134,786
  • 31
  • 255
  • 325

6 Answers6

5

I feel such a fool.

It was because I'd failed to copy the AlbumLibrary.dll to the correct output directory. That meant that Spring couldn't find it - even after I'd fixed the assembly name problem Kent highlighted.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • I had this exact same problem because my project outputs were pointing to different locations. Changing the projects to output the dll's to the same directory fixed everything for me – lomaxx Apr 29 '09 at 05:09
1

I was getting this error because by mistake there was a typo [!*2] in app.config file. Once I took that out , error went away. some thing like this

<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

1

The name after the comma should be the assembly name, which is not necessarily the same as the namespace name.

Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
  • Almost - it was because I'd forgotten to copy the AlbumLibrary dll to the correct output directory. – ChrisF Apr 19 '09 at 18:08
0

You should use tha id attribute instead of name:

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

Also it should be config://spring/objects instead of config://spring/obects.

You need to double check that you have a type called AlbumLibrary in AlbumLibraryWPF namespace defined in AlbumLibraryWPF assembly.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Nope - id still causes the exception to be thrown – ChrisF Apr 19 '09 at 18:03
  • The second was a typo - I tried cut and paste of the code, but Firefox claimed I needed a plugin to be able to see the content - so I typed it out again. – ChrisF Apr 19 '09 at 21:22
-1
  1. Open VS2012 or VS2010 with Administrator Permissions
  2. Config: type="namespace.type, assembly"

Then try running your solution again.

Scott
  • 21,211
  • 8
  • 65
  • 72
leo
  • 1
  • 1
-1

You can try change the type. The type="AlbumLibraryWPF.AlbumLibrary, AlbumLibraryWPF", first parameter means NameSpace and the second parameter (behind the dot) means Solution Name.

  • "AlbumLibraryWPF.AlbumLibrary" = NameSapce name
  • "AlbumLibraryWPF" = solution name
T.Rob
  • 31,522
  • 9
  • 59
  • 103
jason
  • 1