InvalidOperationException: <ClassName xmlns=''/> was not expected

Question: How do you solve error when Deserializing XML in C# Asp.Net 5: "InvalidOperationException: <ClassName xmlns=''/> 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

Edit this Article
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
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy