c# - There was an error generating the XML document -
hi have following code perform xml serialization:
private void savebutton_click(object sender, routedeventargs e) { string savepath; savefiledialog dialogsave = new savefiledialog(); // default file extension dialogsave.defaultext = "txt"; // available file extensions dialogsave.filter = "xml file (*.xml)|*.xml|all files (*.*)|*.*"; // adds extension if user not dialogsave.addextension = true; // restores selected directory, next time dialogsave.restoredirectory = true; // dialog title dialogsave.title = "where want save file?"; // startup directory dialogsave.initialdirectory = @"c:/"; dialogsave.showdialog(); savepath = dialogsave.filename; dialogsave.dispose(); dialogsave = null; formsaving abc = new formsaving(); if (majorversionresultlabel != null && majorversionresultlabel.content != null && majorversionlabel.content.tostring() != string.empty) abc.majorversion = majorversionresultlabel.content.tostring(); //abc.minorversion = minorversionresultlabel.content.tostring(); //abc.projectnumber = projectnumberresultlabel.content.tostring(); //abc.buildnumber = buildnumberresultlabel.content.tostring(); //abc.previousbuildversion = previousbuildversionresultlabel.content.tostring(); abc.startzbuildfrom = startzbuildfromcombobox.selecteditem; using (stream savestream = new filestream(savepath, filemode.create)) { xmlserializer serializer = new xmlserializer(typeof(formsaving)); serializer.serialize(savestream, abc); } }
the error "there error generating xml document" occurs @ serializer.serialize(savestream, abc);
my form saving class:
public class formsaving { public string majorversion { get; set; } public string minorversion { get; set; } public string projectnumber { get; set; } public string buildnumber { get; set; } public string previousbuildversion { get; set; } public object startzbuildfrom { get; set; } }
can me fix this?
edit:
i tried doesnt work well:
under "save button"
abc.startzbuildfrom = startzbuildfromcombobox.selecteditem.tostring();
under "load button"
startzbuildfromcombobox.selecteditem = abc.startzbuildfrom;
here how populate combobox items:
<combobox height="23" margin="577,72,497,0" name="startzbuildfromcombobox" verticalalignment="top"><comboboxitem>library</comboboxitem></combobox>
what data source startzbuildcombobox?
and more type of dataitem of each startzbuildcombobox.selecteditem?
can include innerexception?
most possible reason startzbuildfrom (shouldn't startzbuildfrom?) assigned type xmlserializer has no idea about.
if know type decorate formsaving xmlinclude.
[xmlinclude(typeof(type-of-selected-combobox-selected-item))] public class formsaving { .........
Comments
Post a Comment