Hi,
I am experiencing a strange problem. I am reading and writing xml files via
XmlDocument and XmlTextWriter. In the debugger everything works fine but
outside the debugger (debug or release) I receive the following error: "The
type initializer for "System.Xml.Sch ema.Validator" threw an exception."
I wrote a small console app that contains the problem -- I've just attached
the default class which gets run. Output outside the debugger is as follows
------------------
Creating xml file
Reading xml file
Error reading xml file
The type initializer for "System.Xml.Sch ema.Validator" threw an exception.
Press a key to exit
------------------
I know that this code worked at some point in time and I do not get the
error message when running debug or release from the debugger. Runnning
WinXP SP2 and Visual Studio .Net 2003 (C#). Please feel free to correct me
if I am doing something incorrectly or let me know if it runs error free for
you.
Thanks in advance,
Chris
<snip>
using System;
using System.IO;
using System.Xml;
namespace Test
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class XmlProblem
{
private static string m_sXmlFile = @"C:\temp\test. xml";
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
CreateXMLFile() ;
ReadXMLFile();
Console.WriteLi ne("");
Console.WriteLi ne("Press a key to exit");
Console.ReadLin e();
}
static void CreateXMLFile()
{
StreamWriter sw = null;
try
{
Console.WriteLi ne("Creating xml file");
sw = new StreamWriter(m_ sXmlFile, false);
XmlTextWriter xWriter = new XmlTextWriter(s w);
xWriter.Formatt ing = Formatting.Inde nted;
xWriter.Indenta tion = 3;
xWriter.WriteSt artDocument();
xWriter.WriteSt artElement("App licationSetting s");
xWriter.WriteEn dElement(); // AppSettings
xWriter.WriteEn dDocument();
xWriter.Flush() ;
xWriter.Close() ;
}
catch(Exception ex)
{
Console.WriteLi ne("Error creating xml file " + ex.Message);
}
if (sw != null)
sw.Close();
}
static void ReadXMLFile()
{
StreamReader sr = null;
try
{
Console.WriteLi ne("Reading xml file");
sr = new StreamReader(m_ sXmlFile);
string sFileContents = sr.ReadToEnd();
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(sF ileContents);
}
catch(Exception ex)
{
Console.WriteLi ne("Error reading xml file");
Console.WriteLi ne(ex.Message);
}
if (sr != null)
sr.Close();
}
}
}
</snip>