Skip to content

XmlReader does not find a DTD file #9476

Open

Description

XmlReader does not find a DTD file when ruinning in Azure Function

I have class which deserializes a piece of xml.

    public static TypeToDeserilize ReadFromStream(Stream stream)
    {
        using var xmlReader = XmlReader.Create(stream, new XmlReaderSettings
        {
            XmlResolver = new XmlUrlResolver(),
            ValidationType = ValidationType.DTD,
            DtdProcessing = DtdProcessing.Parse,
            IgnoreWhitespace = true
        });

        var xmlSerializer = new XmlSerializer(typeof(TypeToDeserilize));

        return (TypeToDeserilize)xmlSerializer.Deserialize(xmlReader);
    }

The given Xml contains a reference to a DTD file:
<!DOCTYPE questestinterop SYSTEM "ims_qtiasiv1p2.dtd">

When running in a Web Application it works fine, but when executed in Azure Function App I get error:

Exception while executing function: Convert There is an error in XML document (0, 0). An error has occurred while opening external DTD 'file:///C:/Program Files (x86)/SiteExtensions/Functions/4.24.3/64bit/ims_qtiasiv1p2.dtd': Could not find file 'C:\Program Files (x86)\SiteExtensions\Functions\4.24.3\64bit\ims_qtiasiv1p2.dtd'. Could not find file 'C:\Program Files (x86)\SiteExtensions\Functions\4.24.3\64bit\ims_qtiasiv1p2.dtd'.

I deploy this file into "C:\home\site\wwwroot" but it looks that XmlUrlResolver doesn't look for this file there.

As a workaround I wrote my own xml resolver class and use FunctionAppDirectory from execution context of my
Azure function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions