InvalidOperationException: <ClassName xmlns='http://tempuri.org/'/> was not expected


Question: How do you solve error when Deserializing XML in C# Asp.Net 5: "InvalidOperationException: <ClassName xmlns='http://tempuri.org/'/> was not expected"?

Solution: Do not use WebRequest API to request for XML Response, this will give you problems parsing XML instead use RestClient API to call an External Web Service then deserialize the response using XmlSerializer.

[Important]: Make sure you build your solution before requesting from a Webservice, without building your solution you might experience the same error.

- Another mistake to check is the Model you are trying to Deserialize your response in, make sure it is the right model. If not create a Model from the XML Response by going to Visual Studio "Edit" tabe menu, then "Paste Special" then "Paste XML As Classes" to create a Model classes from XML Response.

See this article https://www.ernestech.com/articles/details/how-to-deserialize-xml-into-object-in-asp.net-core-3.1/3839







For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email AddressContact: [email protected]