0

I have a console application that loads other libraries (DLL's). I'm using Spring.NET. My console application is very simple, load the app.config that is configured through DI to initialize the chosen library.

Code

ContextRegistry.GetContext();

Configuration (app.config)

<?xml version="1.0"?>
<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"/>
        <resource uri="assembly://MyDLL/MyDLL.Config/Services.xml"/>
    </context>
    <objects xmlns="http://www.springframework.net" 
             xmlns:aop="http://www.springframework.net/aop">
    </objects>
</spring>
<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup></configuration>

Each library has its own "services.xml" file. These libraries also use Spring.NET.

<objects xmlns="http://www.springframework.net" 
         xmlns:aop="http://www.springframework.net/aop">

<object id="componentObj" 
        type="MyDLL.Services.ComponentService, MyDLL" 
        singleton="true" />

<object 
 id="componentServiceHost" 
 type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services">
    <property name="TargetName" 
              value="componentObj" />
</object>
</objects>

Getting a excpetion "Process is terminated due to StackOverflowException." If I comment out the <object id="componentServiceHost", the exception does not occur.

The VS console in debug shows

A first chance exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll

A first chance exception of type 'Spring.Objects.Factory.ObjectCreationException' occurred in Spring.Core.dll

A first chance exception of type 'Spring.Objects.Factory.ObjectCreationException' occurred in Spring.Core.dll

Managed (v4.0.30319)' has exited with code -2147023895 (0x800703e9).

user815809
  • 351
  • 5
  • 24
  • 4
    If each library dll has its own configuration file your doing something wrong. You will run into problems there is a reason a single application can only have one configuration file. – Security Hound Jan 03 '13 at 17:42
  • I think OP doesn't like the idea of duplicating his spring.net dependency injection configuration. If so, he is correct that he doesn't want to duplicate this across application configuration files. – Marijn Jan 04 '13 at 08:57

1 Answers1

1

You can also place spring configuration in plain xml files and include those with your library. This way, you can easily share this configuration without the need of sharing an app.config.

You do have to explicitly reference this configuration file in the configuration of your host console application, but that's no duplication. The app.config of your console application host will look like this:

...
<spring>
  <context>
    <resource uri="file://services.xml"/>
    <resource uri="assembly://MyAssembly/MyDataAccess/data-access.xml"/>
  </context>
</spring>

See the spring.net docs how to configure a configuration in xml.

Marijn
  • 10,367
  • 5
  • 59
  • 80
  • ok. Does a library in .NET need an app.config file ? or can I copy the contents of the file to a new xml file and delete the app.config file. – user815809 Jan 04 '13 at 09:44
  • You can delete the library's app.config file, assuming that it only holds the spring configuration. You then place this spring configuration in a separate xml file, that [looks like this](http://www.springframework.net/doc-latest/reference/html/objects.html#objects-factory-instantiation). – Marijn Jan 04 '13 at 09:47
  • copied the contents to a new services.xml file that is embedded resource. loading of the new file has worked but I do not see spring instantiate the objects. – user815809 Jan 04 '13 at 11:57
  • resolved. the issue was caused by removing
    – user815809 Jan 04 '13 at 12:10
  • Now that its instantiated, "Process is terminated due to StackOverflowException." – user815809 Jan 04 '13 at 12:12
  • Please update your question with your new configuration file (app.config + xml file for library). – Marijn Jan 04 '13 at 12:28
  • And note that that the app.config of your aconsole host application should have a `` or similar. – Marijn Jan 04 '13 at 12:38
  • This looks unrelated to your original question. Could you try to see if can retrieve an instance of `componentObj` in your console host to make sure the loading of the configuration from the embedded xml file succeeds. Also note that there is a closing `` tag missing for `componentObj` in the code you pasted. – Marijn Jan 04 '13 at 13:58
  • updated. The componentObj constructor is been called (Console.WriteLine("ComponentService init");). The error now seems to be a Spring.NET issue. Updated the exception with more detail – user815809 Jan 04 '13 at 14:54
  • Looks like a wcf configuration issue, please [see the docs](http://www.springframework.net/doc-latest/reference/html/wcf.html) and consider posting a new question on this error. – Marijn Jan 04 '13 at 15:23
  • the needs to be defined after the closing of the tag. This would need to be done in the app.config file but I wondered if it is possible to import a new xml file after the . The same does not work in this case – user815809 Jan 04 '13 at 17:13
  • This is a wcf configuration issue. I've read some posts on SO on putting wcf config outside app.config files, but that's not really my cup of tea. – Marijn Jan 05 '13 at 10:43