Empty element in XML throws error while deserialization

Maheswaran Monoharan 70 Reputation points

I was trying to de-serialize XML elements to an object. In that XML file, there is an empty element like below <enddate/>. It throws incorrect XML file error.

User's image

I tried options like Isnullable, get set method etc. See below

User's image

Still not able to fix it. And the serialize class looks like this

User's image

Why it is not able to parse this empty element ? any method that works?

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,177 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 29,246 Reputation points Microsoft Vendor

    Hi @Maheswaran Monoharan , Welcome to Microsoft Q&A,

    You have a few options to choose from, one is to use regex to remove all whitespace elements before parsing, which is in case you don't want it.

    If only one or two specific bits are empty, you can choose to add parsing for them individually.

    For details, you can view Deserialize Xml with empty elements in C#

    Please don't add pictures as questions, it won't make it easier for us to test them.

    Best Regards,


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful