Spring.NET XML Configuration Woes

1.8k views Asked by At

I'm trying to load a Spring.NET context from an XML file. I have the following code:

public class ApplicationContextFactory
{
    private static IApplicationContext _context;
    public static IApplicationContext GetContext()
    {
        if (_context == null)
        {
            try
            {
                string data = new StreamReader(
                       Assembly.GetExecutingAssembly().
                       GetManifestResourceStream("Nmspace.Fldr.spring-config.xml"))
                       .ReadToEnd();
                using (var temp = File.CreateText("ctx.xml"))
                    temp.WriteLine(data);
                _context = new XmlApplicationContext("ctx.xml");
               // _context = new XmlApplicationContext(
                    //"assembly://DataLoader/DataLoader/Config.spring-config.xml");
            }
            catch (Exception e)
            {
                string error = e.Message;
            }
        }
        return _context;
    }
}

I'm receiving the following exception:

Line 25 in XML document from file [D:\correct\path\to\ctx.xml] violates the schema. The 'http://www.springframework.net/database:provider' element is not declared.

I get the same error if I pull directly from the assembly. (Commented out lines.)

What's really weird is that I was having no problems until I started a new project and tried to use the configuration in my new project. (This code and configuration file has worked for months in old projects, and still does.)

Edit:

Xmlns declarations:

<objects
    xmlns="http://www.springframework.net"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.net/tx"
    xmlns:db="http://www.springframework.net/database"
    xmlns:aop="http://www.springframework.net/aop"
    xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/schema/objects/spring-objects.xsd
        http://www.springframework.net/schema/tx http://www.springframework.net/schema/tx/spring-tx-1.1.xsd
        http://www.springframework.net/schema/db http://www.springframework.net/schema/db/spring-database.xsd
        http://www.springframework.net/aop http://www.springframework.net/schema/aop/spring-aop-1.1.xsd"
>

The problem line (25):

<db:provider
    id="localDbProvider"
    provider="OracleClient-2.0"
    connectionString=
        "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME = xe))); User Id=cmdb; Password=password;"/>
1

There are 1 answers

1
sbohlen On

Sounds like something has gone wrong with the discovery and registration of the 'well-known-namespace-parsers'. To troubleshoot this, try to declare the namespace alias in the XML file itself as in...

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

...and then see if that works properly. What version of Spring.NET are you using? And is it the same version that is in use in your past project(s) where this same namespace aliasing happens automatically for you--?