question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullReferenceException of ExtendedXmlSerializer.Deserialize()

See original GitHub issue

I’m trying to Deserialize the following XML which was produced by ExtendedXmlSerializer:

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfIPreflightCheck>
	<DiskSpace type="ImageMenu.PreflightChecks.DiskSpace">
		<MinimumMb>20480</MinimumMb>
		<RecommendedMb>40960</RecommendedMb>
		<DiskNumber>0</DiskNumber>
		<Name>Disk 0 Size Check</Name>
	</DiskSpace>
</ArrayOfIPreflightCheck>

Yet I immediately get a NullReferenceException.

Here’s my code:

    public class DiskSpace : IPreflightCheck
    {
                public uint MinimumMb { get; set; }
        public uint RecommendedMb { get; set; }
        public ushort DiskNumber { get; set; }

        public DiskSpace(ushort diskNumber, uint minimumMb, uint recommendedMb)
        {
            DiskNumber = diskNumber;
            MinimumMb = minimumMb;
            RecommendedMb = recommendedMb;

            Name = $"Disk {DiskNumber} Size Check";
        }

        public string Name { get; set; }

        [XmlIgnore]
        public PreflightCheckStatus Status { get; private set; }

        [XmlIgnore]
        public string Message { get; private set; } = "";

        public PreflightCheckStatus Validate()
        {
            ...
        }
    }

    public interface IPreflightCheck
    {
        string Name { get; }

        PreflightCheckStatus Status { get; }

        string Message { get; }

        PreflightCheckStatus Validate();
    }

    var diskSpace = new DiskSpace(0, 20 * 1024, 40 * 1024);
    var t = new ExtendedXmlSerializer();
    var xml = t.Serialize(diskSpace);
    var co = t.Deserialize<DiskSpace>(xml);

Any ideas what the problem might be? I’m using version 1.5

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
WojciechNagorskicommented, Feb 15, 2017

Of course if this issue will take many time in first step we can add only message “Type X doesn’t have public constructor without parameters” or something like that.

0reactions
Mike-E-angelocommented, Mar 19, 2017

I will be closing this issue since it is captured by #8 and opening another issue for the cool Protobuf constructor serialization. Please let me know if I have something misunderstood and/or feel free to re-open this issue as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullReferenceException in ExtendedXmlSerializer #23
Hey, I get a NullReferenceException with this code: var xml = ResourceManager.GetString($"Scenes/{ name }.xml"); var serializer = new ...
Read more >
Deserialization NullReferenceException Object Reference ...
It NEEDS that FindTypeB(id) function to be called, TypeB is made up elsewhere in the program at a very specific moment (which happens...
Read more >
Welcome! — ExtendedXmlSerializer 4.0 documentation
Serialization class with property interface; Serialization circular reference and reference Id; Deserialization of old version of xml; Property encryption ...
Read more >
Extended XML Serializer for .NET
Deserialization xml from standard XMLSerializer; Serialization class, struct, ... SubjectByFactory() : this(null) {} // Used by serializer.
Read more >
XML deserialize creating null object
hello first time using XML, so ifigured i run into some issues I been able to figure out some of them, but I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found