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

XML Deserialization Asp.Net Core Asp.Net 5 XML Web-Service .NET 5 published

Was this page helpful?

Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
Login to Continue




© 2020 - ErnesTech - Privacy