Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1077939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:39:00+00:00 2026-05-16T21:39:00+00:00

I ve been trying in a few different ways to get XmlSerializer.Deserialize to return

  • 0

I ve been trying in a few different ways to get XmlSerializer.Deserialize to return null
however it doesnt seem possible

I tried with a class being null, malformated xml, well formatted xml .

I might be missing something obvious here, but is it possible ?

Just to clarify give a Class MyClass that is serializable I want a similar test to the following to pass

[Fact] //this is a the test attribute when using xUnit
public void When_xml_Something_Then_serialize_returns_null()
{
    string serializedObject = "<?xml version=\"1.0\" encoding=\"utf-8\"?><MyClass xmlns:xsi=\"http://www.w3asdsadasdasd.org/2001/XMLSchema-instance\"></MyClass>";
    using (var stringReader = new StringReader(serializedObject))
    {
        Assert.Null(new XmlSerializer(typeof(MyClass)).Deserialize(stringReader));
    }
}

Tried different things in the serialized string, and i either get an exception or an empty instance of MyClass 🙁
Thanks
NOTE: there was a typo in this question, it is now corrected

NOTE 2: for a more detailed answer look at the comments.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:39:01+00:00Added an answer on May 16, 2026 at 9:39 pm

    Yes, Deserialize can return null when the input does not contain the XML that is expected. This is frequently seen when there is confusion of the XML namespaces. If the input contains a root element with the expected name, but in a different namespace, then null will be returned.

    This is often seen when dealing with ASMX web services or with Web References, especially web references against RPC-style services, where the messages are described in terms of the XSD type of the message, and not in terms of the element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying this a few different ways, but I'm reaching the conclusion that
I've been trying a few different ways to filter finding of specific nodes within
Ive been trying unsuccessfully for a few days now to get a button to
I've been trying to get a visualisation going for a few days. I'm generating
I've been trying to use a few different gems for displaying googlemaps within rails
I have been trying for a few days to get Sonata Media Bundle working
Hey all, i have been trying for a few minutes on this problem and
Been trying to understand shared pointer for a few days now and it feels
I've been trying now for a few hours to move our Magento installation from
For the past few days I have been trying to play any sound over

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.