Click here to Skip to main content
15,891,184 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionDeadlock issue in batch processing Pin
Dimpal1701-Sep-11 4:38
Dimpal1701-Sep-11 4:38 
AnswerRe: Deadlock issue in batch processing Pin
Wendelius3-Sep-11 4:35
mentorWendelius3-Sep-11 4:35 
AnswerRe: Deadlock issue in batch processing Pin
jschell3-Sep-11 10:24
jschell3-Sep-11 10:24 
QuestionSaving FlowDocument to XPS causes viewer to go blank Pin
Geron31-Aug-11 22:17
Geron31-Aug-11 22:17 
AnswerRe: Saving FlowDocument to XPS causes viewer to go blank [modified] Pin
Pradeep Shukla6-Sep-11 17:46
professionalPradeep Shukla6-Sep-11 17:46 
QuestionObject serialization problem Pin
columbos1492730-Aug-11 23:58
columbos1492730-Aug-11 23:58 
AnswerRe: Object serialization problem Pin
Richard Andrew x6431-Aug-11 6:54
professionalRichard Andrew x6431-Aug-11 6:54 
AnswerRe: Object serialization problem Pin
Columbus-MCSD4-Sep-11 17:53
Columbus-MCSD4-Sep-11 17:53 
you need to show some code for a better answer

anyway, here's how to serialize xml
C#
class myClass(){/*define class*/}

void SerializeToXML(myClass object)
 {
   XmlSerializer serializer = new XmlSerializer(typeof(myClass));
   TextWriter textWriter = new StreamWriter(/*filename here*/);
   serializer.Serialize(textWriter, object);
   textWriter.Close();
 }


As you saw in your app, the XMLSerializer also doesn't support circular references. If you need this kind of flexibility, you should consider binary serialization.

Here's how you can serialize to binary

C#
void SerializeToBinary(myClass object, MemoryStream stream)
{
    stream.Seek(0, System.IO.SeekOrigin.Begin); 
    BinaryFormatter formatter = new BinaryFormatter();
    formatter.Serialize(stream, object);
}


Use XmlTextWriter to manually create an XML file, and use XmlTextWriter.WriteBase64 to write your binary data into the file. Make sure you add a "length" attribute.

here's how to deserialize the binary back into an object

First make an XmlTextReader, navigate to the Element you wrote and create a MemoryStream

then create a byte[array] and put the data in it

xr.MoveToAttribute("length");
xr.ReadAttributeValue();
int length = Int32.Parse(xr.Value);
byte[] data = new byte[length];
xr.ReadBase64(data, 0, length);
stream.Write(data, 0, length);

now you can deserialize your object

C#
stream.Seek(0, System.IO.SeekOrigin.Begin);
IFormatter formatter = new BinaryFormatter();
myClass object = (myClass)formatter.Deserialize(stream);

QuestionI am getting this kind of error,pls help Pin
jitendra rajbher30-Aug-11 23:43
jitendra rajbher30-Aug-11 23:43 
AnswerRe: I am getting this kind of error,pls help Pin
Dave Kreskowiak31-Aug-11 2:09
mveDave Kreskowiak31-Aug-11 2:09 
GeneralRe: I am getting this kind of error,pls help Pin
jitendra rajbher31-Aug-11 3:43
jitendra rajbher31-Aug-11 3:43 
GeneralRe: I am getting this kind of error,pls help Pin
Shameel31-Aug-11 4:19
professionalShameel31-Aug-11 4:19 
GeneralThanks,but I saw that code but i am not able to see may data Pin
jitendra rajbher31-Aug-11 20:47
jitendra rajbher31-Aug-11 20:47 
GeneralRe: I am getting this kind of error,pls help Pin
Dave Kreskowiak31-Aug-11 5:40
mveDave Kreskowiak31-Aug-11 5:40 
QuestionIn VB .NET how do we get the new row ID number in an access database table BEFORE inserting the new row? Pin
aeskan30-Aug-11 4:12
aeskan30-Aug-11 4:12 
AnswerRe: In VB .NET how do we get the new row ID number in an access database table BEFORE inserting the new row? Pin
Pete O'Hanlon30-Aug-11 4:17
mvePete O'Hanlon30-Aug-11 4:17 
GeneralRe: In VB .NET how do we get the new row ID number in an access database table BEFORE inserting the new row? Pin
aeskan30-Aug-11 9:38
aeskan30-Aug-11 9:38 
AnswerRe: In VB .NET how do we get the new row ID number in an access database table BEFORE inserting the new row? Pin
Jitheshvijayan8-Sep-11 20:55
Jitheshvijayan8-Sep-11 20:55 
GeneralRe: In VB .NET how do we get the new row ID number in an access database table BEFORE inserting the new row? Pin
aeskan8-Sep-11 22:40
aeskan8-Sep-11 22:40 
QuestionNot able to find Event icon in Property window [modified] Pin
KIDYA29-Aug-11 21:24
KIDYA29-Aug-11 21:24 
AnswerRe: Not able to find Event icon in Property window Pin
RobCroll30-Aug-11 2:10
RobCroll30-Aug-11 2:10 
Questionhow to implement OOP in vb.net? Pin
visualst29-Aug-11 19:47
visualst29-Aug-11 19:47 
AnswerRe: how to implement OOP in vb.net? Pin
Bert Mitton31-Aug-11 3:17
professionalBert Mitton31-Aug-11 3:17 
GeneralRe: how to implement OOP in vb.net? Pin
visualst2-Sep-11 0:33
visualst2-Sep-11 0:33 
QuestionRe: how to implement OOP in vb.net? Pin
Bert Mitton3-Sep-11 6:43
professionalBert Mitton3-Sep-11 6:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.