By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,759 Members | 1,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,759 IT Pros & Developers. It's quick & easy.

Exception thrown outside debugger but not in debugger

P: n/a
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 I receive the following error: "The
type initializer for "System.Xml.Schema.Validator" threw an exception.".
When running from the debugger (debug or release) no exception is thrown.

I wrote a small console app that replicates 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.Schema.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.WriteLine("");
Console.WriteLine("Press a key to exit");
Console.ReadLine();
}

static void CreateXMLFile()
{
StreamWriter sw = null;

try
{
Console.WriteLine("Creating xml file");

sw = new StreamWriter(m_sXmlFile, false);
XmlTextWriter xWriter = new XmlTextWriter(sw);
xWriter.Formatting = Formatting.Indented;
xWriter.Indentation = 3;
xWriter.WriteStartDocument();
xWriter.WriteStartElement("ApplicationSettings");
xWriter.WriteEndElement(); // AppSettings
xWriter.WriteEndDocument();
xWriter.Flush();
xWriter.Close();
}
catch(Exception ex)
{
Console.WriteLine("Error creating xml file " + ex.Message);
}

if (sw != null)
sw.Close();
}

static void ReadXMLFile()
{
StreamReader sr = null;

try
{
Console.WriteLine("Reading xml file");

sr = new StreamReader(m_sXmlFile);
string sFileContents = sr.ReadToEnd();

XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(sFileContents);
}
catch(Exception ex)
{
Console.WriteLine("Error reading xml file");
Console.WriteLine(ex.Message);
}

if (sr != null)
sr.Close();
}

}
}

</snip>

Mar 10 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I ran your code under the debugger, then in release mode. No errors. Set the
debugger to break on all exceptions, No errors.

--
Warm Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley 2006
Blog: http://msmvps.com/blogs/Alvin/
-------------------------------------------------------

"Chris Stiefeling" <Ch*************@discussions.microsoft.com> wrote in
message news:C9**********************************@microsof t.com...
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 I receive the following error: "The
type initializer for "System.Xml.Schema.Validator" threw an exception.".
When running from the debugger (debug or release) no exception is thrown.

I wrote a small console app that replicates 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.Schema.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.WriteLine("");
Console.WriteLine("Press a key to exit");
Console.ReadLine();
}

static void CreateXMLFile()
{
StreamWriter sw = null;

try
{
Console.WriteLine("Creating xml file");

sw = new StreamWriter(m_sXmlFile, false);
XmlTextWriter xWriter = new XmlTextWriter(sw);
xWriter.Formatting = Formatting.Indented;
xWriter.Indentation = 3;
xWriter.WriteStartDocument();
xWriter.WriteStartElement("ApplicationSettings");
xWriter.WriteEndElement(); // AppSettings
xWriter.WriteEndDocument();
xWriter.Flush();
xWriter.Close();
}
catch(Exception ex)
{
Console.WriteLine("Error creating xml file " + ex.Message);
}

if (sw != null)
sw.Close();
}

static void ReadXMLFile()
{
StreamReader sr = null;

try
{
Console.WriteLine("Reading xml file");

sr = new StreamReader(m_sXmlFile);
string sFileContents = sr.ReadToEnd();

XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(sFileContents);
}
catch(Exception ex)
{
Console.WriteLine("Error reading xml file");
Console.WriteLine(ex.Message);
}

if (sr != null)
sr.Close();
}

}
}

</snip>

Mar 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.