473,602 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Xml validation exception only occurs outside debugger - VS 2003 C#

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>
Mar 9 '06 #1
2 2873
Chris,

I tried to repro your issue, but I couldnt. I copied your code, compiled it
and ran it on 1.1 with XP SP2, outside of vc# 2003.

Could you attach the entire stack trace and message for the exception? Dont
catch the exception and let it show up on the screen.

Thanks,
Amol
"Chris Stiefeling" <Ch************ *@discussions.m icrosoft.com> wrote in
message news:0C******** *************** ***********@mic rosoft.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 (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>

Apr 11 '06 #2
Thanks for your reply -- I almost missed it until I went searching on Google
for the same problem again.

I'm able to reproduce the problem on any Xml file (even ones produced by
MSFT programs). Looks like the source is actually a null reference in the
regex classes.

I can also send along my exe if it is helpful.

Here's the stack trace:

Unhandled Exception: System.TypeInit ializationExcep tion: The type
initializer fo
r "System.Xml.Sch ema.Validator" threw an exception. --->
System.TypeInit ializati
onException: The type initializer for
"System.Xml.Sch ema.DatatypeImp lementation"
threw an exception. ---> System.TypeInit ializationExcep tion: The type
initializ
er for "System.Xml.Sch ema.Datatype_la nguage" threw an exception. --->
System.Typ
eInitialization Exception: The type initializer for
"System.Text.Re gularExpressio
ns.RegexCharCla ss" threw an exception. ---> System.NullRefe renceException:
Objec
t reference not set to an instance of an object.
at System.Text.Reg ularExpressions .RegexCharClass ..cctor()
--- End of inner exception stack trace ---
at System.Text.Reg ularExpressions .RegexCharClass ..ctor()
at System.Text.Reg ularExpressions .RegexParser.Sc anCharClass(Boo lean
caseInsen
sitive, Boolean scanOnly)
at System.Text.Reg ularExpressions .RegexParser.Sc anRegex()
at System.Text.Reg ularExpressions .RegexParser.Pa rse(String re,
RegexOptions o
p)
at System.Text.Reg ularExpressions .Regex..ctor(St ring pattern,
RegexOptions op
tions)
at System.Xml.Sche ma.Datatype_lan guage..cctor()
--- End of inner exception stack trace ---
at System.Xml.Sche ma.Datatype_lan guage..ctor()
at System.Xml.Sche ma.DatatypeImpl ementation..cct or()
--- End of inner exception stack trace ---
at
System.Xml.Sche ma.XmlSchemaDat atype.FromXmlTo kenizedType(Xml TokenizedType
token)
at System.Xml.Sche ma.Validator..c ctor()
--- End of inner exception stack trace ---
at System.Xml.Sche ma.Validator..c tor(XmlNameTabl e nameTable,
XmlValidatingRe a
der reader)
at System.Xml.XmlV alidatingReader ..ctor(XmlReade r reader)
at System.Xml.XmlD ocument.CreateV alidatingReader (XmlTextReader tr)
at System.Xml.XmlD ocument.LoadXml (String xml)
at Test.XmlProblem .ReadXMLFile()
at Test.XmlProblem .Main(String[] args)

Thanks for your help.

Chris

"Amol Kher [MSFT]" wrote:
Chris,

I tried to repro your issue, but I couldnt. I copied your code, compiled it
and ran it on 1.1 with XP SP2, outside of vc# 2003.

Could you attach the entire stack trace and message for the exception? Dont
catch the exception and let it show up on the screen.

Thanks,
Amol
"Chris Stiefeling" <Ch************ *@discussions.m icrosoft.com> wrote in
message news:0C******** *************** ***********@mic rosoft.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 (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>


Apr 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5983
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
0
1684
by: Diana Bulthaupt | last post by:
Hello, have implemented a global exception handler. If an exception occurs, the event OnThreadException will be called. In this method I call Debugger.Launch() to start a Debugger. This works so far but the call stack doesn't show the path to the location where the exception occured to obtain more information about the failure. When OnThreadException is called , the call stack is cleared. How can it be accomplished, that debugging...
5
2694
by: Peter Steele | last post by:
We have an application that when it runs in the IDE in debug mode an unhandled exception is occurring in a system header file associated with STL stirngs. The actual statement that crashes is return ::memcmp(_First1, _First2, _Count); On inspecting these variables, the strings are in fact equal when the exception occurs and _Count is the right size. As a test I replaced this code in the system include file with a for loop to do the...
9
2308
by: RalphTheExpert | last post by:
I'm getting different behavior if my code is running under the debugger or not. I have modified Winmain to look like this: // Copyright (C) 2002 Microsoft Corporation // All rights reserved. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
5
3412
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
9
2201
by: Claudio Di Flumeri | last post by:
Hello all, I've added a global exception handler to my application in this way: Sub Main() AddHandler Application.ThreadException, AddressOf ThreadException AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException Application.Run(Main)
5
3292
by: Samuel R. Neff | last post by:
When you have an unhandled exception in vb.net how do you view the exception information in the debugger? In C# the debugger creates a local variable that points to the exception and you can view it in one of the windows (autos or locals, don't remember which). That doesn't appear to be the case with vb.net. I also tried using the command window to inspect "Err" but that gave nothing useful (always empty).
1
2854
by: Chris Stiefeling | last post by:
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...
5
7917
by: pcnerd | last post by:
I'm trying to create a program that plots randomly colored pixels on a bitmap & then displays the bitmap. When I run the program, I see the pixels being plotted down the left side of the form. When it gets to the bottom, the "Argument out of range exception" occurs. So, obviously the program starts. The Help tells me that the argument isn't within the range of values, but it doesn't explain how to fix the problem. So the Help doesn't help!...
0
7993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5867
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2418
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1254
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.