I am trying to use the Configuration.AddDocument() method, but I am getting an exception ("ArgumentException: reader"). I am using NHibernate version 0.83.
I started a debug session to step into the NHibernate.Cfg.Configuration source code and found out that the exception is being raised because of this sequence code inside the AddDocument method:
Code:
public Configuration AddDocument(XmlDocument doc)
{
XmlNodeReader nodeReader = null
try
{
nodeReader = new XmlNodeReader(doc);
AddXmlReader(nodeReader);
return this;
}
catch(Exception e)
{
}
}
The exception is happening inside the AddXmlReader() method, which calls the LoadMappingDocument() method. The first thing this method tries to do is to build a ValidatingReader based on the given XmlReader parameter.
Code:
public LoadMappingDocument(XmlReader hbmReader)
{
/* This lines raises the exception */
XmlValidatingReader validatingReader = new XmlValidatingReader(hbmReader);
}
The problem is that XmlValidatingReader only accepts XmlTextReader. Passing a XmlNodeReader instance (as it is happenning in this case) causes the ArgumentException("reader") to be thrown.