Its been working fine for ages, I spend a couple of days on unrelated parts
of the system, and I can no longer write files (or read old ones).
The error message I get is "There was an error reflecting type
WindowsApplication1.Form1.savestructure'.".
Here is the code, which has worked fine for ages:
public class savestructure
{
public List<textaslot> alist;
public int speed, size;
public int squareorcircle;
}
(textaslot is an awful class, with lots of public members. However, I
haven't added very much into it in the last few days, and taking what I have
doesn't seem to help, although it was a lot of work to try. Nor can I
understand why this would fail on write, so its not a compatibility issue.)
.
.
private void savethisconfig()
{
savestructure thissave = new savestructure();
thissave.alist = slotcollection;
thissave.speed = (int)speedUpDown.Value;
thissave.squareorcircle = mainrotatortype;
thissave.size = (int)sizeUpDown.Value;
serialiseandsave(thissave);
}
public void serialiseandsave(savestructure allslots)
{
XmlSerializer mySerializer = new
XmlSerializer(typeof(savestructure));
... and that's where it crashes.
This is really spooking me, as it also means I can't load any of the dozens
of files I have created. I have no idea where to go after getting this
error - what to try.
Any suggestions?
Marc Gravell - 25 Feb 2008 15:04 GMT
First - check the seccessive inner-exceptions; there might be more
detail available.
Second - for deserializing this, you might want the list to be auto-
created in the constructor; IIRC, generally (for IList<T> etc) it just
calls .Add() for each child item - it doesn't expect to create the
list first [but this would impact deserialization, not serialization].
Third - very hard to tell without something short and reproducable.
Marc
Peter Webb - 25 Feb 2008 15:39 GMT
> First - check the seccessive inner-exceptions; there might be more
> detail available.
And when I did, it identified that I didn't have a parameterless constructor
for one type, and that fixed it.
I didn't even know you could get this information - when you click on the
"show inner exception" hyperlink it takes you to a useless MSDN page -
thankyou for pointing it out to me.
Marc Gravell - 25 Feb 2008 15:50 GMT
> and that fixed it
good to hear
> it takes you to a useless MSDN page
Yes; that window isn't as useful as it could be; those links are very
easy (too easy) to click when you actually mean "*show* me the
exception" (which is the "View Detail..." link). Personally, I'd like
it if the IDE simply listed each nested Message in turn, with perhaps
a right-click option on each to show the MSDN information about that
specific exception.
Marc
Richard Blewett - 25 Feb 2008 15:13 GMT
> Its been working fine for ages, I spend a couple of days on unrelated
> parts of the system, and I can no longer write files (or read old ones).
[quoted text clipped - 43 lines]
>
> Any suggestions?
Have you generated the serialization assembly using sgen.exe?
If thats the case you may be picking up the old one which no longer
serializes correctly

Signature
Regards
Richard Blewett
DevelopMentor
http://www.dotnetconsult.co.uk/weblog2