What is the format of xml context definition file that XmlApplicationContext(sFileName) will read?

StackOverflow https://stackoverflow.com/questions/301770

  •  08-07-2019
  •  | 
  •  

Question

All the examples that I can search online use the App.Config mode of specifying the context definition retrieved by

contextToGetSprungObjects = ContextRegistry.GetContext(contextname)

I want to use

contextToGetSprungObjects = new XmlApplicationContext(sXmlFileName)

(I'm calling into a DLL (that needs Spring.net) from another executable (MsWord) so app.config approach is out). I tried sneaking in MyDll.dll.config.. didn't fly. On using the XmlApplicationContext approach to read it from a specified xml file, I get the following error

{"Error registering object with name '' defined in 'file [D:\\Work\\Seven\\WordAutomation\\ContentControls\\WordDocument1\\bin\\debug\\MyWPFPlotPopup.dll.config]' : There is no parser registered for namespace ''\r\n<configSections><sectionGroup name=\"spring\"><section name=\"context\" type=\"Spring.Context.Support.ContextHandler, Spring.Core\" /></sectionGroup><section name=\"log4net\" type=\"log4net.Config.Log4NetConfigurationSectionHandler, log4net\" /></configSections>"}

Which leads me to believe that the two approaches need their xml in a differently shaped bottle. I searched high and low but the schema for the xml that is needed eludes me.. everything I can find uses X.exe.config or Web.config. Can someone point me to a valid xml context defintion for Spring.net?

<spring>
    <context>
        <context name="MyApplication">
            <resource uri="file://Resources/MyApplicationContext.xml"/>
        </context>
    </context>
</spring>

I think this is the relevant section of the app.config that I want Spring.net to readd

Was it helpful?

Solution

Spring.NET docs are a good exercise in pain

did you check out the introductorily section "Basics - containers and objects" of the reference docs? Imho chapters 5.2.1 "Configuration Metadata" and 5.2.2 "Instantiating the container" pretty clearly demonstrate what you were trying to achieve. What were your pain points? We'd be happy to receive your improvement suggestions!

I'd also like to suggest you post Spring for .NET relevant questions to our community forums - it is more likely to get your questions answered there.

cheers, Erich

OTHER TIPS

Finally cleared this hurdle. XmlApplicationContext doesn't read the intermediate mapping xml in app.config... it reads the contents pointed to be the resource element directly. It won't read the app.config format - which is used by ContextRegistry class in Spring.net. Spring.net docs are a good exercise in pain.

context = new XmlApplicationContext("file://Resources/MyApplicationContext.xml");

where this xml is of the following form.

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
  <object id="Wilma" type="WhatIsSpring.Wilma, WhatIsSpring"/>
  <object id="Fred" type="WhatIsSpring.Fred, WhatIsSpring">
    <property name="TheDependency" ref="Wilma"/>
  </object>
</objects>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top