1
votes

Spring version : 2.0.0.40000 Runtime : .NET 4.5

Taking the example shown here www.springframework.net/.../objects.html and in the API http://springframework.net/docs/1.3..../webframe.html - ContextHandler

I have the following

Code:

<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 name="child">
    <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
    </sectionGroup> 
  </sectionGroup> 
</configSections>

<spring>
  <objects xmlns="http://www.springframework.net">
    <import resource="assembly://ProjectDLL/Config/Spring.xml"/> 
  </objects>

  <child>
    <objects xmlns="http://www.springframework.net">
      <object name="eventLog"
          type="System.Diagnostics.EventLog, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
          >
        <constructor-arg type="string" name="logName" value="v1"  />
        <constructor-arg type="string" name="machineName" value="."  />
        <constructor-arg type="string" name="source" value="v1"  />
      </object>
    </objects>
  </child>  

  <context name="Parent">
    <resource uri="config://spring/objects"/>
    <context name="child">
    <resource uri="config://spring/child/objects"/>
    </context>
  </context>
</spring>

Calling

ContextRegistry.GetContext();

of any context names results in

Message --- Error creating context 'ChildContext': Errored while postprocessing an object factory.

I've tried all the various naming for including Child, ChildContext, Children, all resulting in the same error.

In my example, I use a resource file that contains my objects ( ), if I do not import my own XML file, it works but importing it means that the child does not work. If I define the child in the same xml file, I get "Error creating context 'Parent': There are multiple root elements"

I know this is most likely a configuration issue and would appreciate any help.

1
Please post the configuration in "your own xml file". Are you using any object post processors such as a property placeholder configurer there? - Marijn
I did a quick test with basic working configuration similar to yours is on github; the configuation in app.config works for me. - Marijn
@Marijn after a couple of days of trying this I failed back to putting everything into app.config file - and then suffered the same issue. One of my class's must be doing something funny that causes this so I reverted to uses depends-on to sequence the startup. - user815809
@Marijn The reason I needed to do this was because my WCF services hosted by Spring.ServiceModel.Activation.ServiceHostFactoryObject got instantiated early and the WCF service would get called to early and prevent all the other objects defined in the configuration getting loaded. The thread that was loading the objects would go into a WaitSleepJoin state. Ordering using depends-on is now preventing this. - user815809
Ah, good find! Note that you can answer your own question too, that might be helpful to other that visit your question. - Marijn

1 Answers

1
votes

Having not fully understood the error I was getting or why, the workaround was to use "depends-on" for startup. The spring xsd defines quiet a few here http://www.springframework.net/xsd/spring-objects.xsd