Jeeby
Jeeby

Reputation: 1464

VS2010 Debugging Weirdness

I have posted details about this issue in another post (but the focus of that post is another issue which is what I'm trying to debug)... the other post is here: XmlSerializer.Deserialize for a sub class (not an array)

In a nutshell, here is what is happening:

I'm deserializing from an xml file to classes in C# using XmlSerializer.Deserialize().

If I take a look at the object that is created by the Deserialize function, it shows me that one of the objects within it is null, and if i then Serialize that back out to an xml file it comes through with null values.

But, if I don't take a look at the object after Deserializing, and just continue on to Serialize back to XML, all the values are there and Serialize correctly.

So it seems that the debugger is nuking my object's values, or writing them all back to null.

I've tried changing the parameterless constructor of the object to write default values to the properties, but the result in the debugger is still null (so it's not reinstantiating the object as I suspected it might be doing).

The Deserializer is working fine for every other object except this one (which is one level deeper than all the others in the XML, but in the class hierarchy it is at the same level as the others. I've tried moving it to a level deeper in the class hierarchy but that doesn't make a difference.

I'm sure this issue is with the Visual Studio debugger and not the Deserializer, but I don't know how to verify this. Does anybody else have any ideas, or seen anything like this in VS before?

I think I might try to debug on a different machine today - maybe it's something to do with my environment. Resharper maybe? So very weird... Any other advice would be greatly appreciated.

Upvotes: 1

Views: 34

Answers (1)

Jeeby
Jeeby

Reputation: 1464

Ahahahaha... I'm such a goof! Had a workmate run through this with me, and we found something really silly that i'd done, namely:

public string ToString()
{
    Name = null;
    OfficeName = null;
    Address1 = null;
    Address2 = null;
    City = null;
    State = null;
    Postcode = null;
    Phone = null;
    Banner = null;
    Logo = null;

    StringBuilder sb = new StringBuilder();
    sb.Append(String.Format("Name:{0} / OfficeName: {1} / Address1: {2} / Address2: {3} / City: {4} / State: {5} / Postcode: {6} / Phone: {7} / Banner: {8} / Logo: {9}",
        Name, OfficeName, Address1, Address2, City, State, Postcode, Phone, Banner, Logo));
    return sb.ToString();
}

So every time i took a look at the object in the debugger, it was calling my ToString() override, which was then nuking all the values.

Don't i feel sheepish. LOL

Upvotes: 1

Related Questions