Tech Off Post

Single Post Permalink

View Thread: Does this entity bug exist in .NET framework 2.0?
  • User profile image
    Grumpy

    I found an odd bug in the .NET framework v1.1.  I don't have room to load v2.0 on my drive.  Can someone tell me whether this bug exists in v2.0?  The bug test is a simple VB console app:

    Module EntryPoint
    Sub Main()
    Dim x0 As Xml.XmlDocument = New Xml.XmlDocument
    Dim xr As Xml.XmlTextReader = New Xml.XmlTextReader("..\EntityTest.xml")
    Dim xv As Xml.XmlValidatingReader = New Xml.XmlValidatingReader(xr)
    Try
    x0.Load(xv)
    Console.Error.WriteLine("Value [copy]: {0}", x0.DocumentType.Entities.GetNamedItem("copy").InnerText)
    Console.Error.WriteLine("Value [lt]: {0}", x0.DocumentType.Entities.GetNamedItem("lt").InnerText) ' Throws System.InvalidOperationException
     Catch ex As Exception
    Console.Error.WriteLine("Error: {0}", ex.Message)
    Console.Error.WriteLine("Value [lt]: {0}", x0.DocumentType.Entities.GetNamedItem("lt").InnerText) ' Returns empty string!!
    End Try
    End Sub
    End Module

    This produces an exception about the state of the object, yet the state seems to be fine where it pulled the text of the copy entity. Worst, if you trap the .GetNamedItem("lt").InnerText and execute it again, it doesn't throw an error but return a zero length string!!
     
    The xml file (EntityTest.xml) validates just fine with a variety of xml parsers:
    <?xml version="1.0" encoding="utf-8" ?> 
    <!DOCTYPE doc
    [
    <!ENTITY nbsp "&#160;">
    <!ENTITY copy "&#169;">
    <!ENTITY lt "&#38;#60;">
    <!ENTITY gt "&#38;#62;">
    <!ELEMENT doc (#PCDATA)>
    ]
    >
    <doc>&lt;&copy;&gt;</doc>

    Thanks, Grumpy.