Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Does this entity bug exist in .NET framework 2.0?

Back to Forum: Tech Off
  • 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.

  • User profile image
    mawcc

    Result seems to be the same in 2.0, although XmlValidatingReader is marked obsolete now:

    C:\Scripts>\WINDOWS\Microsoft.NET\Framework\v2.0.50215\vbc.exe test.vb
    Microsoft (R) Visual Basic Compiler version 8.0.50215.44
    for Microsoft (R) .NET Framework version 2.0.50215.44
    Copyright (C) Microsoft Corporation 1987-2003. All rights reserved.

    C:\Scripts\test.vb(5) : warning BC40000: 'System.Xml.XmlValidatingReader' is obs
    olete: 'Use XmlReader created by XmlReader.Create() method using appropriate Xml
    ReaderSettings instead. http://go.microsoft.com/fwlink/?linkid=14202'">http://go.microsoft.com/fwlink/?linkid=14202'

            Dim xv As Xml.XmlValidatingReader = New Xml.XmlValidatingReader(xr)
                      ~~~~~~~~~~~~~~~~~~~~~~~
    C:\Scripts\test.vb(5) : warning BC40000: 'System.Xml.XmlValidatingReader' is obs
    olete: 'Use XmlReader created by XmlReader.Create() method using appropriate Xml
    ReaderSettings instead. http://go.microsoft.com/fwlink/?linkid=14202'">http://go.microsoft.com/fwlink/?linkid=14202'

            Dim xv As Xml.XmlValidatingReader = New Xml.XmlValidatingReader(xr)
                                                    ~~~~~~~~~~~~~~~~~~~~~~~

    C:\Scripts>test
    Value [copy]: ©
    Error: Operation is not valid due to the current state of the object.
    Value [lt]:

  • User profile image
    Sven Groot

    The exception type is a bit deceptive, and what's happening here has nothing to do with the order in which you do things. It seems this exception occurs whenever you try to get the value of an entity that is a redefinition of a predefined entity. In this case, lt and gt are predefined entities, so you cannot access their value, while copy and nbsp are not predefined, so they work correctly (even after the exception has occurred).
    I don't know why this happens, but it doesn't seem to adversely effect the parsing and validating of the document.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.