© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•14mo ago•
34 replies
MC

Loading XML results in list longer than XML

I'm struggling with this, am not sure what to search for, and I can't really post a code snippet as it's part of a larger project.

I have a List<int> that is part of a class that gets saved/serialized to XML.
When I load the XML, it's creating a List multiple times longer than what is in the XML.
I've created breakpoints and watch the List, and during XML loading, the List goes from an exception (as expected because default class value is a new empty list), to 152 once loaded, while the XML/List only contains 16 elements.

The strange thing that I've noticed, is the additional values are identical to default values that I had previously set in the Class.

A bit of background is that the List was originally an Array containing 8 values, which I then expanded to 16 values. However for some reason the second 8 values weren't getting loaded, which is why I converted it to a List. However I'm now getting far many more elements available, rather than too few.

I have been through all references to the List, and the only one that writes values, is my code for storing values into the List, which results in only 16 values being stored to the XML.
However when the XML is loaded, it adds the old default 16 values to the start of the List, so the saved values get overwritten.

I'm currently wondering if this is some kind of caching bug in VS, as I can't find any reason for the old default values to even be known (they are all commented out in the code)
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

XMl: How to convert IEnumerable<XmlNode> to XmlNodeList ?
C#CC# / help
3y ago
❔ xml
C#CC# / help
4y ago
XML in an API
C#CC# / help
2y ago