XmlSerializer throws exception in Azure Functions v2 but not elsewhere
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 215
- Avg merge
- 4h 2m
- Merged PRs (30d)
- 1
Description
The line of code in this code block where the XmlSerializer tries to deserialize the XML throws an exception when invoked by a v2 Azure Functions app but succeeds when invoked by other .NET apps; e.g., ASP.NET, Windows Service, Windows Forms. The Azure function and other apps are all targeting .NET 4.8. The same code block also succeeds in Azure Functions v1 targeting .NET 4.7.
```
public static Obj GetRootObjFrom(string xml)
{
try
{
if (xml != null)
{
var xmlDoc = XDocument.Parse(xml);
var obixTypeDef = typeof(Tridium.Obj);
var reader = new StringReader(xml);
var deserializer = new XmlSerializer(obixTypeDef, xmlDoc.Root.Name.NamespaceName);
var obixObj = (Tridium.Obj)deserializer.Deserialize(reader);
return obixObj;
}
}
catch (Exception ex)
{
// TODO: Log exception.
}
return null;
}
```
This is the XML content that I am testing with:
```
```
This exception is thrown:
The ReadElementContentAsString method is not supported on node type Attribute. Line 3, position 73.
I am developing the Azure function under Windows 10 using the following:
VS.NET 2019 Pro v16.1.6
Microsoft.NET.Sdk.Functions v1.0.29
Microsoft.Azure.WebJobs v3.0.10
Microsoft.Azure.WebJobs.Extensions.ServiceBus v3.1.0-beta3
I generate the Tridium.Obj class in the code block using the pro version of the xsd2code++ VS.NET extension from XSD schema derived from: http://obix.org/ns/schema/1.0.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.