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;"/>