473,569 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlTextReader ReadChars can enter an infinate loop when reading st

The following code will enter an infinate loop when in ReadChars. I can only
make it happen when reading a Stream and with this particular XML. If I use
the ReadInnerXml call rather than my own ReadElementBody AsXml the code works,
but is less efficent. ReadElementBody AsXml is required by my application
with .Net Framework 1.1.

The code breaks on the second call to ReadElementBody AsXml with the inner xml:
</EGDConfigExtens ion>
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterHmiResour ces"><HmiResour ces>
<HmiResource Name="hgyugyg" />
</HmiResources></EGDConfigExtens ion>
This is bad behavior, so I felt it should be posted. Maybe it is already
know to be fixed in SP1 (hopefully forthcoming).

Regards,
Rick

--- code that breaks ---
private void ReadXml()
{
FileStream fs = File.OpenRead(@ "MasterSymbolTa ble.xml");
XmlTextReader reader = new XmlTextReader(f s, XmlNodeType.Ele ment, null);
reader.MoveToCo ntent();
reader.ReadToDe scendant("EGDCo nfigExtension") ;
string xml = ReadElementBody AsXml(reader);
reader.Read();
xml = ReadElementBody AsXml(reader);
}

private string ReadElementBody AsXml(XmlTextRe ader reader)
{
int startingLineNum ber = reader.LineNumb er;
int startingLinePos ition = reader.LinePosi tion;
int startingDepth = reader.Depth;
bool startingElement IsEmpty = reader.IsEmptyE lement;
string startingName = reader.Name;

System.Diagnost ics.Debug.Asser t(reader.NodeTy pe == XmlNodeType.Ele ment,
"Node type must be Element.",
"ReadElementBod yAsXml should be called when the reader is positioned on
an element. It will simply return null if it is not, but the intention is
for it to be used to read element content.");

char[] buffer = new char[512];
int totalRead = 0;
int i;
while ((i = reader.ReadChar s(buffer, totalRead, buffer.Length -
totalRead)) 0)
{
totalRead += i;
if (reader.Depth <= startingDepth)
{
// Even though we read chars, the LineNumber and LinePosition do not
change
// unless we read a node. We don't want to read any more unless we are
// on a child node. But we also need to make sure that we are not still
// on the same node that we started with, since we could have some very
// big nodes. It is hard to tell if ReadChars returned because it did
// not have any more content buffered or if it got to the end of a node.
// If at the end of a node, which node?
// This code fixes SCR 2923.
if (reader.NodeTyp e != XmlNodeType.Ele ment)
break; // We must not be on the node we started on.
}
if (reader.NodeTyp e == XmlNodeType.End Element && reader.Depth ==
startingDepth)
break;
if (totalRead == buffer.Length)
{
char[] newBuf = new char[buffer.Length + 512];
Buffer.BlockCop y(buffer, 0, newBuf, 0, totalRead * 2); // Each char is
2 bytes.
buffer = newBuf;
}
}

string innerXml = null;
if (totalRead 0)
innerXml = new string(buffer, 0, totalRead);
else
innerXml = null;

return innerXml;
}

----- XML file MasterSymbolTab le.Xml ---
<?xml version="1.0" encoding="utf-8"?>
<?GeCssClass type="GeIndsysN etworkCoe.EgdCo nfig.EgdMasterS ymbolTable,
EgdCoeConfig"?>
<MasterEgdSymbo lTable EGDSpecVersion= "3.04" ConfigTimeSecs= "1160762827 "
ConfigTimeNSecs ="704238500" xmlns="http://geindustrial.co m/EGD" Name="Demo">
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterAlarms">< AlarmClasses>
<AlarmClass Name="Alarm" Description="De fault Class for Process Alarms"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Red" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Red" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Trip" Description="De fault Class for Convertor Trips"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Maroon" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Maroon" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="System" Description="De fault Class for WorkstationST
System alarms" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Teal"
AlarmForeground Color="White" AckBackgroundCo lor="White"
AckForegroundCo lor="Teal" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="Diagnosti c" Description="De fault Class for Process
Diagnostics" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Red"
AlarmForeground Color="White" AckBackgroundCo lor="White"
AckForegroundCo lor="Red" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="Hold" Description="De fault Class for Holds" DescAlt=""
NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Yellow" AlarmForeground Color="Black"
AckBackgroundCo lor="Black" AckForegroundCo lor="Yellow" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Diag" Description="De fault Class for Process Diagnostics"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Red" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Red" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Sys" Description="De fault Class for WorkstationST System
alarms" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Teal"
AlarmForeground Color="White" AckBackgroundCo lor="White"
AckForegroundCo lor="Teal" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="TEST" Description="Te st Alarm Class" DescAlt=""
NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Maroon" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Maroon" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="OpSet" Description="Al arm Class for Operator Setpoint
Events" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Yellow"
AlarmForeground Color="Black" AckBackgroundCo lor="Black"
AckForegroundCo lor="Yellow" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="SOE" Description="De fault Class for Sequence of event"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Yellow" AlarmForeground Color="Black"
AckBackgroundCo lor="Black" AckForegroundCo lor="Yellow" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Event" Description="De fault Class for Process Events"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Yellow" AlarmForeground Color="Black"
AckBackgroundCo lor="Black" AckForegroundCo lor="Yellow" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
</AlarmClasses></EGDConfigExtens ion>
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterHmiResour ces"><HmiResour ces>
<HmiResource Name="hgyugyg" />
</HmiResources></EGDConfigExtens ion>
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterPlantArea s"><PlantAre as>
<PlantAreaPat h Path="Plant" />
<PlantAreaPat h Path="Plant.Pla ntArea01" />
<PlantAreaPat h Path="Plant.Pla ntArea01.PlantA rea21" />
<PlantAreaPat h Path="Plant.Pla ntArea02" />
<PlantAreaPat h Path="Plant.Pla ntArea04" />
<PlantAreaPat h Path="Plant.Pla ntArea14" />
<PlantAreaPat h Path="Plant.Pla ntArea15" />
</PlantAreas></EGDConfigExtens ion>
</MasterEgdSymbol Table>

Oct 26 '06 #1
13 3224
I forgot to mention, the infinate loop is in .Net Framework 2.0. I have the
hotfixes (KB924895 and KB922271) (as well as 2 security updates) installed.
--
Rick
"Rick" wrote:
The following code will enter an infinate loop when in ReadChars. I can only
make it happen when reading a Stream and with this particular XML. If I use
the ReadInnerXml call rather than my own ReadElementBody AsXml the code works,
but is less efficent. ReadElementBody AsXml is required by my application
with .Net Framework 1.1.

The code breaks on the second call to ReadElementBody AsXml with the inner xml:
</EGDConfigExtens ion>
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterHmiResour ces"><HmiResour ces>
<HmiResource Name="hgyugyg" />
</HmiResources></EGDConfigExtens ion>
This is bad behavior, so I felt it should be posted. Maybe it is already
know to be fixed in SP1 (hopefully forthcoming).

Regards,
Rick

--- code that breaks ---
private void ReadXml()
{
FileStream fs = File.OpenRead(@ "MasterSymbolTa ble.xml");
XmlTextReader reader = new XmlTextReader(f s, XmlNodeType.Ele ment, null);
reader.MoveToCo ntent();
reader.ReadToDe scendant("EGDCo nfigExtension") ;
string xml = ReadElementBody AsXml(reader);
reader.Read();
xml = ReadElementBody AsXml(reader);
}

private string ReadElementBody AsXml(XmlTextRe ader reader)
{
int startingLineNum ber = reader.LineNumb er;
int startingLinePos ition = reader.LinePosi tion;
int startingDepth = reader.Depth;
bool startingElement IsEmpty = reader.IsEmptyE lement;
string startingName = reader.Name;

System.Diagnost ics.Debug.Asser t(reader.NodeTy pe == XmlNodeType.Ele ment,
"Node type must be Element.",
"ReadElementBod yAsXml should be called when the reader is positioned on
an element. It will simply return null if it is not, but the intention is
for it to be used to read element content.");

char[] buffer = new char[512];
int totalRead = 0;
int i;
while ((i = reader.ReadChar s(buffer, totalRead, buffer.Length -
totalRead)) 0)
{
totalRead += i;
if (reader.Depth <= startingDepth)
{
// Even though we read chars, the LineNumber and LinePosition do not
change
// unless we read a node. We don't want to read any more unless we are
// on a child node. But we also need to make sure that we are not still
// on the same node that we started with, since we could have some very
// big nodes. It is hard to tell if ReadChars returned because it did
// not have any more content buffered or if it got to the end of a node.
// If at the end of a node, which node?
// This code fixes SCR 2923.
if (reader.NodeTyp e != XmlNodeType.Ele ment)
break; // We must not be on the node we started on.
}
if (reader.NodeTyp e == XmlNodeType.End Element && reader.Depth ==
startingDepth)
break;
if (totalRead == buffer.Length)
{
char[] newBuf = new char[buffer.Length + 512];
Buffer.BlockCop y(buffer, 0, newBuf, 0, totalRead * 2); // Each char is
2 bytes.
buffer = newBuf;
}
}

string innerXml = null;
if (totalRead 0)
innerXml = new string(buffer, 0, totalRead);
else
innerXml = null;

return innerXml;
}

----- XML file MasterSymbolTab le.Xml ---
<?xml version="1.0" encoding="utf-8"?>
<?GeCssClass type="GeIndsysN etworkCoe.EgdCo nfig.EgdMasterS ymbolTable,
EgdCoeConfig"?>
<MasterEgdSymbo lTable EGDSpecVersion= "3.04" ConfigTimeSecs= "1160762827 "
ConfigTimeNSecs ="704238500" xmlns="http://geindustrial.co m/EGD" Name="Demo">
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterAlarms">< AlarmClasses>
<AlarmClass Name="Alarm" Description="De fault Class for Process Alarms"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Red" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Red" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Trip" Description="De fault Class for Convertor Trips"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Maroon" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Maroon" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="System" Description="De fault Class for WorkstationST
System alarms" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Teal"
AlarmForeground Color="White" AckBackgroundCo lor="White"
AckForegroundCo lor="Teal" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="Diagnosti c" Description="De fault Class for Process
Diagnostics" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Red"
AlarmForeground Color="White" AckBackgroundCo lor="White"
AckForegroundCo lor="Red" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="Hold" Description="De fault Class for Holds" DescAlt=""
NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Yellow" AlarmForeground Color="Black"
AckBackgroundCo lor="Black" AckForegroundCo lor="Yellow" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Diag" Description="De fault Class for Process Diagnostics"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Red" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Red" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Sys" Description="De fault Class for WorkstationST System
alarms" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Teal"
AlarmForeground Color="White" AckBackgroundCo lor="White"
AckForegroundCo lor="Teal" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="TEST" Description="Te st Alarm Class" DescAlt=""
NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Maroon" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Maroon" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="OpSet" Description="Al arm Class for Operator Setpoint
Events" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Yellow"
AlarmForeground Color="Black" AckBackgroundCo lor="Black"
AckForegroundCo lor="Yellow" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="SOE" Description="De fault Class for Sequence of event"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Yellow" AlarmForeground Color="Black"
AckBackgroundCo lor="Black" AckForegroundCo lor="Yellow" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Event" Description="De fault Class for Process Events"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Yellow" AlarmForeground Color="Black"
AckBackgroundCo lor="Black" AckForegroundCo lor="Yellow" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
</AlarmClasses></EGDConfigExtens ion>
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterHmiResour ces"><HmiResour ces>
<HmiResource Name="hgyugyg" />
</HmiResources></EGDConfigExtens ion>
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterPlantArea s"><PlantAre as>
<PlantAreaPat h Path="Plant" />
<PlantAreaPat h Path="Plant.Pla ntArea01" />
<PlantAreaPat h Path="Plant.Pla ntArea01.PlantA rea21" />
<PlantAreaPat h Path="Plant.Pla ntArea02" />
<PlantAreaPat h Path="Plant.Pla ntArea04" />
<PlantAreaPat h Path="Plant.Pla ntArea14" />
<PlantAreaPat h Path="Plant.Pla ntArea15" />
</PlantAreas></EGDConfigExtens ion>
</MasterEgdSymbol Table>
Oct 26 '06 #2
Hi Rick,

Thanks for providing me with the xml file and the code. According to your
description, I installed the two hotfixes on my machine and tried to
reproduce it on my machine. However, the code works fine and I didn't get
an infinate loop. I also set some breakpoints in the code and check for the
LineNumber and LinePosition properties. They are advancing properly.

Have you tried this code on another machine? If it is in an infinate loop,
did the thread hang?

Kevin Yu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Oct 27 '06 #3
Hi Kevin,

Yes, this is happening on several PCs. I could get you a dump from windbg
if you want.

If it makes a difference, I'm running the code from a Windows Form in the
constructor. Here is the VS2005 callstack:
System.Xml.dll! System.Xml.XmlT extReaderImpl.P arseQName(bool isQName =
true, int startOffset, out int colonPos = -1) + 0x10f bytes
System.Xml.dll! System.Xml.XmlT extReaderImpl.I ncrementalRead( ) + 0x508 bytes
System.Xml.dll! System.Xml.XmlT extReaderImpl.I ncrementalRead( System.Array
array, int index, int count) + 0x79 bytes
System.Xml.dll! System.Xml.XmlT extReaderImpl.R eadChars(char[] buffer, int
index, int count) + 0xbc bytes
System.Xml.dll! System.Xml.XmlT extReader.ReadC hars(char[] buffer, int
index, int count) + 0x15 bytes
> ReadCharsSample .exe!ReadCharsS ample.Form1.Rea dElementBodyAsX ml(System.Xml.X mlTextReader reader = {Element, Name="EGDConfig Extension"}) Line 46 + 0x15 bytes C#
ReadCharsSample .exe!ReadCharsS ample.Form1.Rea dXml() Line 29 + 0x9 bytes C#
ReadCharsSample .exe!ReadCharsS ample.Form1.For m1() Line 18 + 0x7 bytes C#
ReadCharsSample .exe!ReadCharsS ample.Program.M ain() Line 17 + 0x13 bytes C#
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!Sy stem.AppDomain. ExecuteAssembly (string assemblyFile,
System.Security .Policy.Evidenc e assemblySecurit y, string[] args) + 0x32 bytes

Microsoft.Visua lStudio.Hosting Process.Utiliti es.dll!Microsof t.VisualStudio. HostingProcess. HostProc.RunUse rsAssembly() + 0x2b bytes
mscorlib.dll!Sy stem.Threading. ThreadHelper.Th readStart_Conte xt(object
state) + 0x3b bytes

mscorlib.dll!Sy stem.Threading. ExecutionContex t.Run(System.Th reading.Executi onContext
executionContex t, System.Threadin g.ContextCallba ck callback, object state) +
0x81 bytes
mscorlib.dll!Sy stem.Threading. ThreadHelper.Th readStart() + 0x40 bytes
The loaded modules are:

'ReadCharsSampl e.vshost.exe' (Managed): Loaded
'C:\WINDOWS\ass embly\GAC_32\ms corlib\2.0.0.0_ _b77a5c561934e0 89\mscorlib.dll ',
No symbols loaded.
'ReadCharsSampl e.vshost.exe' (Managed): Loaded
'C:\WINDOWS\ass embly\GAC_MSIL\ Microsoft.Visua lStudio.Hosting Process.Utiliti es\8.0.0.0__b03 f5f7f11d50a3a\M icrosoft.Visual Studio.HostingP rocess.Utilitie s.dll', Symbols loaded.
'ReadCharsSampl e.vshost.exe' (Managed): Loaded
'C:\WINDOWS\ass embly\GAC_MSIL\ System.Windows. Forms\2.0.0.0__ b77a5c561934e08 9\System.Window s.Forms.dll', Symbols loaded.
'ReadCharsSampl e.vshost.exe' (Managed): Loaded
'C:\WINDOWS\ass embly\GAC_MSIL\ System\2.0.0.0_ _b77a5c561934e0 89\System.dll',
Symbols loaded.
'ReadCharsSampl e.vshost.exe' (Managed): Loaded
'C:\WINDOWS\ass embly\GAC_MSIL\ System.Drawing\ 2.0.0.0__b03f5f 7f11d50a3a\Syst em.Drawing.dll' , Symbols loaded.
'ReadCharsSampl e.vshost.exe' (Managed): Loaded
'C:\WINDOWS\ass embly\GAC_MSIL\ Microsoft.Visua lStudio.Hosting Process.Utiliti es.Sync\8.0.0.0 __b03f5f7f11d50 a3a\Microsoft.V isualStudio.Hos tingProcess.Uti lities.Sync.dll ', Symbols loaded.
'ReadCharsSampl e.vshost.exe' (Managed): Loaded
'C:\ReadCharsXm lIssue\ReadChar sSample\bin\Deb ug\ReadCharsSam ple.vshost.exe' ,
Symbols loaded.
'ReadCharsSampl e.vshost.exe' (Managed): Loaded
'C:\WINDOWS\ass embly\GAC_32\Sy stem.Data\2.0.0 .0__b77a5c56193 4e089\System.Da ta.dll', Symbols loaded.
'ReadCharsSampl e.vshost.exe' (Managed): Loaded
'C:\WINDOWS\ass embly\GAC_MSIL\ System.Deployme nt\2.0.0.0__b03 f5f7f11d50a3a\S ystem.Deploymen t.dll', Symbols loaded.
'ReadCharsSampl e.vshost.exe' (Managed): Loaded
'C:\WINDOWS\ass embly\GAC_MSIL\ System.Xml\2.0. 0.0__b77a5c5619 34e089\System.X ml.dll', Symbols loaded.
The thread 0x60c has exited with code 0 (0x0).
The thread 0x1548 has exited with code 0 (0x0).
SRCSRV: The module
'C:\ReadCharsXm lIssue\ReadChar sSample\bin\Deb ug\ReadCharsSam ple.exe' does not
contain source server information.
'ReadCharsSampl e.vshost.exe' (Managed): Loaded
'C:\ReadCharsXm lIssue\ReadChar sSample\bin\Deb ug\ReadCharsSam ple.exe', Symbols
loaded.
SRCSRV: The module
'C:\ReadCharsXm lIssue\ReadChar sSample\bin\Deb ug\ReadCharsSam ple.exe' does not
contain source server information.
'ReadCharsSampl e.vshost.exe' (Managed): Loaded
'C:\WINDOWS\ass embly\GAC_MSIL\ System.Configur ation\2.0.0.0__ b03f5f7f11d50a3 a\System.Config uration.dll', Symbols loaded.
SRCSRV: The module
'C:\ReadCharsXm lIssue\ReadChar sSample\bin\Deb ug\ReadCharsSam ple.exe' does not
contain source server information.
SRCSRV: The module
'C:\ReadCharsXm lIssue\ReadChar sSample\bin\Deb ug\ReadCharsSam ple.exe' does not
contain source server information.
SRCSRV: The module
'C:\ReadCharsXm lIssue\ReadChar sSample\bin\Deb ug\ReadCharsSam ple.exe' does not
contain source server information.

--
Rick
"Kevin Yu [MSFT]" wrote:
Hi Rick,

Thanks for providing me with the xml file and the code. According to your
description, I installed the two hotfixes on my machine and tried to
reproduce it on my machine. However, the code works fine and I didn't get
an infinate loop. I also set some breakpoints in the code and check for the
LineNumber and LinePosition properties. They are advancing properly.

Have you tried this code on another machine? If it is in an infinate loop,
did the thread hang?

Kevin Yu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Oct 27 '06 #4
More information.... I tried just copying the text from my XML into a file
and as you reported... it reads correctly.

What I missed when pasting the XML in the post, we create our XML with UTF8
encoding, so the XmlTextWriter writes 3 bytes in the begining of the file.
If these 3 bytes are not present, ReadChars reads fine. If they are present,
I get the hang up.

The basic code we use to create an XML file is:
FileStream fileStream = new FileStream(@"Ne wFile.xml", FileMode.Create ,
FileAccess.Writ e);
XmlTextWriter writer = new XmlTextWriter(f ileStream, Encoding.UTF8);

....
write the xml
....
writer.Close();

The 3 bytes at the begining of the file are EF BB BF in value.
--
Rick
"Rick" wrote:
I forgot to mention, the infinate loop is in .Net Framework 2.0. I have the
hotfixes (KB924895 and KB922271) (as well as 2 security updates) installed.
--
Rick
"Rick" wrote:
The following code will enter an infinate loop when in ReadChars. I can only
make it happen when reading a Stream and with this particular XML. If I use
the ReadInnerXml call rather than my own ReadElementBody AsXml the code works,
but is less efficent. ReadElementBody AsXml is required by my application
with .Net Framework 1.1.

The code breaks on the second call to ReadElementBody AsXml with the inner xml:
</EGDConfigExtens ion>
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterHmiResour ces"><HmiResour ces>
<HmiResource Name="hgyugyg" />
</HmiResources></EGDConfigExtens ion>
This is bad behavior, so I felt it should be posted. Maybe it is already
know to be fixed in SP1 (hopefully forthcoming).

Regards,
Rick

--- code that breaks ---
private void ReadXml()
{
FileStream fs = File.OpenRead(@ "MasterSymbolTa ble.xml");
XmlTextReader reader = new XmlTextReader(f s, XmlNodeType.Ele ment, null);
reader.MoveToCo ntent();
reader.ReadToDe scendant("EGDCo nfigExtension") ;
string xml = ReadElementBody AsXml(reader);
reader.Read();
xml = ReadElementBody AsXml(reader);
}

private string ReadElementBody AsXml(XmlTextRe ader reader)
{
int startingLineNum ber = reader.LineNumb er;
int startingLinePos ition = reader.LinePosi tion;
int startingDepth = reader.Depth;
bool startingElement IsEmpty = reader.IsEmptyE lement;
string startingName = reader.Name;

System.Diagnost ics.Debug.Asser t(reader.NodeTy pe == XmlNodeType.Ele ment,
"Node type must be Element.",
"ReadElementBod yAsXml should be called when the reader is positioned on
an element. It will simply return null if it is not, but the intention is
for it to be used to read element content.");

char[] buffer = new char[512];
int totalRead = 0;
int i;
while ((i = reader.ReadChar s(buffer, totalRead, buffer.Length -
totalRead)) 0)
{
totalRead += i;
if (reader.Depth <= startingDepth)
{
// Even though we read chars, the LineNumber and LinePosition do not
change
// unless we read a node. We don't want to read any more unless we are
// on a child node. But we also need to make sure that we are not still
// on the same node that we started with, since we could have some very
// big nodes. It is hard to tell if ReadChars returned because it did
// not have any more content buffered or if it got to the end of a node.
// If at the end of a node, which node?
// This code fixes SCR 2923.
if (reader.NodeTyp e != XmlNodeType.Ele ment)
break; // We must not be on the node we started on.
}
if (reader.NodeTyp e == XmlNodeType.End Element && reader.Depth ==
startingDepth)
break;
if (totalRead == buffer.Length)
{
char[] newBuf = new char[buffer.Length + 512];
Buffer.BlockCop y(buffer, 0, newBuf, 0, totalRead * 2); // Each char is
2 bytes.
buffer = newBuf;
}
}

string innerXml = null;
if (totalRead 0)
innerXml = new string(buffer, 0, totalRead);
else
innerXml = null;

return innerXml;
}

----- XML file MasterSymbolTab le.Xml ---
<?xml version="1.0" encoding="utf-8"?>
<?GeCssClass type="GeIndsysN etworkCoe.EgdCo nfig.EgdMasterS ymbolTable,
EgdCoeConfig"?>
<MasterEgdSymbo lTable EGDSpecVersion= "3.04" ConfigTimeSecs= "1160762827 "
ConfigTimeNSecs ="704238500" xmlns="http://geindustrial.co m/EGD" Name="Demo">
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterAlarms">< AlarmClasses>
<AlarmClass Name="Alarm" Description="De fault Class for Process Alarms"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Red" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Red" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Trip" Description="De fault Class for Convertor Trips"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Maroon" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Maroon" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="System" Description="De fault Class for WorkstationST
System alarms" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Teal"
AlarmForeground Color="White" AckBackgroundCo lor="White"
AckForegroundCo lor="Teal" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="Diagnosti c" Description="De fault Class for Process
Diagnostics" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Red"
AlarmForeground Color="White" AckBackgroundCo lor="White"
AckForegroundCo lor="Red" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="Hold" Description="De fault Class for Holds" DescAlt=""
NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Yellow" AlarmForeground Color="Black"
AckBackgroundCo lor="Black" AckForegroundCo lor="Yellow" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Diag" Description="De fault Class for Process Diagnostics"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Red" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Red" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Sys" Description="De fault Class for WorkstationST System
alarms" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Teal"
AlarmForeground Color="White" AckBackgroundCo lor="White"
AckForegroundCo lor="Teal" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="TEST" Description="Te st Alarm Class" DescAlt=""
NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Maroon" AlarmForeground Color="White"
AckBackgroundCo lor="White" AckForegroundCo lor="Maroon" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="OpSet" Description="Al arm Class for Operator Setpoint
Events" DescAlt="" NormalBackgroun dColor="White"
NormalForegroun dColor="Black" AlarmBackground Color="Yellow"
AlarmForeground Color="Black" AckBackgroundCo lor="Black"
AckForegroundCo lor="Yellow" IsIntrinsic="tr ue" NormalSeverity= "350"
ActiveSeverity= "500" />
<AlarmClass Name="SOE" Description="De fault Class for Sequence of event"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Yellow" AlarmForeground Color="Black"
AckBackgroundCo lor="Black" AckForegroundCo lor="Yellow" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
<AlarmClass Name="Event" Description="De fault Class for Process Events"
DescAlt="" NormalBackgroun dColor="White" NormalForegroun dColor="Black"
AlarmBackground Color="Yellow" AlarmForeground Color="Black"
AckBackgroundCo lor="Black" AckForegroundCo lor="Yellow" IsIntrinsic="tr ue"
NormalSeverity= "350" ActiveSeverity= "500" />
</AlarmClasses></EGDConfigExtens ion>
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterHmiResour ces"><HmiResour ces>
<HmiResource Name="hgyugyg" />
</HmiResources></EGDConfigExtens ion>
<EGDConfigExten sion Company="http://pdweb.salem.ge. com"
ExtensionCode=" MasterPlantArea s"><PlantAre as>
<PlantAreaPat h Path="Plant" />
<PlantAreaPat h Path="Plant.Pla ntArea01" />
<PlantAreaPat h Path="Plant.Pla ntArea01.PlantA rea21" />
<PlantAreaPat h Path="Plant.Pla ntArea02" />
<PlantAreaPat h Path="Plant.Pla ntArea04" />
<PlantAreaPat h Path="Plant.Pla ntArea14" />
<PlantAreaPat h Path="Plant.Pla ntArea15" />
</PlantAreas></EGDConfigExtens ion>
</MasterEgdSymbol Table>
Oct 27 '06 #5
Rick wrote:

The 3 bytes at the begining of the file are EF BB BF in value.
That is the BOM (byte order mark for UTF-8), you can avoid that by using
e.g.

XmlTextWriter writer = new XmlTextWriter(f ileStream, new
UTF8Encoding(tr ue));

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 27 '06 #6
Martin Honnen wrote:
Rick wrote:

>The 3 bytes at the begining of the file are EF BB BF in value.

That is the BOM (byte order mark for UTF-8), you can avoid that by using
e.g.

XmlTextWriter writer = new XmlTextWriter(f ileStream, new
UTF8Encoding(tr ue));
I misread the API, you need e.g.

XmlTextWriter writer = new XmlTextWriter(f ileStream, new
UTF8Encoding(fa lse));

to avoid the BOM.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 27 '06 #7
Should I avoid writing the BOM or is that required to tell a reader the
content is UTF8 encoded? My feeling is these bytes should be there. I want
unicode in my XML.

Also, if the BOM was writen by XMLTextWriter, should the XMLTextReader's
ReadChars exhibit the infinite loop behavior?
--
Rick
"Martin Honnen" wrote:
Martin Honnen wrote:
Rick wrote:

The 3 bytes at the begining of the file are EF BB BF in value.
That is the BOM (byte order mark for UTF-8), you can avoid that by using
e.g.

XmlTextWriter writer = new XmlTextWriter(f ileStream, new
UTF8Encoding(tr ue));

I misread the API, you need e.g.

XmlTextWriter writer = new XmlTextWriter(f ileStream, new
UTF8Encoding(fa lse));

to avoid the BOM.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 27 '06 #8
Rick wrote:
Should I avoid writing the BOM or is that required to tell a reader the
content is UTF8 encoded? My feeling is these bytes should be there. I want
unicode in my XML.
For UTF-8 the BOM is optional, see
<http://www.unicode.org/faq/utf_bom.html#BO M>
Also, if the BOM was writen by XMLTextWriter, should the XMLTextReader's
ReadChars exhibit the infinite loop behavior?
Usually Microsoft's XML parsers know how to deal with an UTF-8 BOM. I am
not sure why you get the loop problem but I have not read the complete
thread. I mainly tried to explain what the bytes you see are and to
provide a work around.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 27 '06 #9
Thanks for the post. Again, a workaround is for me to use ReadInnerXml
rather than building my own. The method using ReadChars was required in .Net
framework 1.1, but ReadInnerXml works for 2.0. The side effect is poorer
performance, so I'm interested if ReadChars could be fixed in a future .Net
framework release. I want to stick to writing the BOM for legacy reasons. I
have a lot of production code writing the BOM that I'll need to support
reading.
--
Rick
"Martin Honnen" wrote:
Rick wrote:
Should I avoid writing the BOM or is that required to tell a reader the
content is UTF8 encoded? My feeling is these bytes should be there. I want
unicode in my XML.

For UTF-8 the BOM is optional, see
<http://www.unicode.org/faq/utf_bom.html#BO M>
Also, if the BOM was writen by XMLTextWriter, should the XMLTextReader's
ReadChars exhibit the infinite loop behavior?

Usually Microsoft's XML parsers know how to deal with an UTF-8 BOM. I am
not sure why you get the loop problem but I have not read the complete
thread. I mainly tried to explain what the bytes you see are and to
provide a work around.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 27 '06 #10

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

Similar topics

4
5357
by: Meir S. | last post by:
I think the following is a bug in XmlTextReader: I need to process large XMLs, that are typically constructed of many small elements nested in the root element. Each inner element represents a command, so I have to parse and execute them according to the order they appear in the ROOT element. I don't want to use XmlDocument for the...
3
4206
by: keldan | last post by:
I am hoping someone on this list can shed some light on the below issue for me. I am using XmlTextReader to read from an XML file. Unfortunately, an exception is thrown ("Index was outside the bounds of the array.") when the reader reaches the DOCTYPE. If I remove it everything works fine. Should I be handling the DOCTYPE someway before...
4
11358
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This should have worked fine since the class in question was already being serialized and deserialized as part of a Web service interface. What I found was...
5
9195
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef RelatedID="118"/> <PersonName> <NameTitle Value="Mr"/> <FirstName>Clint</FirstName> <OtherName/> <AlsoKnownAs>Mr C Eastwood</AlsoKnownAs>
1
16408
by: Emsi | last post by:
Hello, how can I read values of child nodes with the XmlTextReader? File format: <root> <items> <item> <field1>value1</field1> <field2>value2</field2>
1
4419
by: soupaman | last post by:
Im trying to output some filtered xml using the xmlTextReader I know the code and commenting needs cleaned up and eventually plan to add the values to a dataset. currently what this is doing is matching the filters, runs into the response.write and outputs nothing. I've used the dbgclr to verify that the filters are matching and it is hitting...
3
3753
by: Newton | last post by:
Hi, I receive XML document from input and I would like to read it several times... My declaration is XmlTextReader XMLInputReader = new XmlTextReader(fileImport.PostedFile.InputStream); I am reading it like this
0
1079
by: Dave | last post by:
I'm reading chars from a file and displaying them in a label on a form. Following is a listing of the code section. Could anyone tell me the best way to do this? What I have works but wanted to know if there is a better way. I had some trouble converting the binaryreader->readchars so that they could be added to the label. Thanks for your...
4
1687
by: Paul Bromley | last post by:
I thought that XMLTextReader would be simple to use, but I have run into problems with it! I seem to have great difficulty extrcting the text of specific elements from a very simple XML file. I have a very simple XML file that I wish to parse using Xmltextreader, but I seem to be having a lot of poblems with it. I have a subroutine that I...
0
7698
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...
0
7924
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. ...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6284
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...
1
5513
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...
0
3653
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...
1
2113
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
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
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...

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.