473,796 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception thrown outside debugger but not in debugger

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.Sch ema.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.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 10 '06 #1
1 2861
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.m icrosoft.com> wrote in
message news:C9******** *************** ***********@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 I receive the following error: "The
type initializer for "System.Xml.Sch ema.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.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 10 '06 #2

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

Similar topics

2
2357
by: kpax | last post by:
Hi, While debugging my application when an explicit exception is thrown by me (or an implicit exception is thrown internally) which is not handled anywhere in the stack, the execution breaks as expected but I can not continue. I try start the execution and go back to running mode, but it always comes to the same line where the exception is first thrown.
9
2213
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)
2
1324
by: Nak | last post by:
Hi there, I'm just curious as to something. I have just added an exception handler at the entry point to my application, within the IDE any unhandled exceptions fallback to this and enable me to disable a dialog of my liking. Now if I run the application outside of the IDE I recieve the standard "Unhandled exception" dialog provided by .NET giving me the ability to continue or quit. I wasn't actually aware that exception handling...
3
31146
by: Pieter | last post by:
Hi, I have a Windows Forms application (VB.NET 2.0) which uses a Class Library in C#. The application runs fine, but when I run it in debug mode, I get several "A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll" -exceptions that are shown in the Immediate window of Visual Studio 2005. I want to get rid of these exceptions, but I can(t find where they occur.
2
2892
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 (debug or release) I receive the following error: "The type initializer for "System.Xml.Schema.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...
6
1797
by: Robin Riley | last post by:
Hi, I have a .NET solution that contains a dll project and a tester application project which, of course, invokes the dll. The dll project has exception handling in it. What's happening is that when I run the executable from within the .NET studio environment, thrown exceptions are caught and handled correctly (both debug and release mode). However, if I run the executable from outside the .NET studio, none of the exceptions get caught....
132
5626
by: Zorro | last post by:
The simplicity of stack unraveling of C++ is not without defective consequences. The following article points to C++ examples showing the defects. An engineer aware of defects can avoid hard-to-find bugs. http://distributed-software.blogspot.com/2007/01/c-exception-handling-is-defective.html Regards, zorabi@ZHMicro.com http://www.zhmicro.com http://distributed-software.blogspot.com
4
4146
by: Terry Olsen | last post by:
I have a class where I throw a new exception from a method My calling code (in a different class) is wrapped in a Try/Catch block, but it's not catching. Instead the IDE is highlighting the ThrowNew Exception line in the class and saying it was unhandled. Looking for some help. Thanks!
6
3395
by: Phillip Taylor | last post by:
I don't like the way every time I write a bad sql query the debugger takes me to the database access code. It's extremely stable and reliable and the exceptions being thrown are because of SQL queries data passed to it. I don't want to handle or supress exceptions at that point in the application, but rather ignore them so the debugger handles them in the correct place, further up the call stack. In java I could normally add a "throws...
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10465
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...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
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
7558
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
5453
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...
1
4127
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
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
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.