Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
AnswerRe: Need help with datatable Pin
Gergo Bogdan26-Sep-13 1:58
Gergo Bogdan26-Sep-13 1:58 
GeneralRe: Need help with datatable Pin
superselector26-Sep-13 2:09
superselector26-Sep-13 2:09 
GeneralRe: Need help with datatable Pin
Gergo Bogdan26-Sep-13 3:03
Gergo Bogdan26-Sep-13 3:03 
GeneralRe: Need help with datatable Pin
superselector26-Sep-13 3:31
superselector26-Sep-13 3:31 
AnswerRe: Need help with datatable Pin
Ron Nicholson26-Sep-13 3:41
professionalRon Nicholson26-Sep-13 3:41 
QuestionGet Images from scanner in c# Pin
sanket16425-Sep-13 21:49
sanket16425-Sep-13 21:49 
AnswerRe: Get Images from scanner in c# Pin
Pete O'Hanlon25-Sep-13 22:39
mvePete O'Hanlon25-Sep-13 22:39 
QuestionProblem using DataContractSerializer Pin
larsp77725-Sep-13 4:27
larsp77725-Sep-13 4:27 
Hi! I trying to use DataContractSerializer to save objects with crossreference. It´s two lists of objects.

I doesn´t get a error but even though the file is created it does´t work to get it back.

Maybe it´s better to use BinaryFormatter?

Some of my code:

C#
DataContractSerializer xs = new DataContractSerializer(typeof(List<Customer>));
        DataContractSerializer xs2 = new DataContractSerializer(typeof(List<Book>));

Book-class:

    [KnownType(typeof(FaktaBok))]
    [KnownType(typeof(BarnBok))]
    [KnownType(typeof(SportBok))]
    [DataContractAttribute()]
    public class Book
    {
        [DataMember]
        protected int isbn = 0;

        [DataMember]
        protected string titel = null;

        [DataMember]
        protected string author;

        [DataMember]
        protected int price;

        [DataMember]
        protected String isType = null;

        [DataMember]
        protected Kund biblioteksKund = null;

One derived class:

[DataContractAttribute()]
     public class SportBok : Bok
     {
         [DataMember]
         private string sport;


Serialize: 

 using (Stream s = File.Create(path))
                {
                    xs.WriteObject(s, CustomerList);
                }

                using (Stream s2 = File.Create(path2))
                {
                    xs2.WriteObject(s2, BookList);
                }


DeSerialize:

 if (File.Exists(path))
 {
      using (Stream s = File.OpenRead(path))
       {
             CustomerList = (List<Kund>)xs.ReadObject(s);
       }
 }

if (File.Exists(path2))
{
      using (Stream s2 = File.OpenRead(path2))
      {
          BookList = (List<Bok>)xs2.ReadObject(s2);
      }
}

AnswerRe: Problem using DataContractSerializer Pin
Member 424999726-Sep-13 20:22
Member 424999726-Sep-13 20:22 
GeneralRe: Problem using DataContractSerializer Pin
larsp77726-Sep-13 21:53
larsp77726-Sep-13 21:53 
GeneralRe: Problem using DataContractSerializer Pin
Member 424999726-Sep-13 23:26
Member 424999726-Sep-13 23:26 
GeneralRe: Problem using DataContractSerializer Pin
larsp77727-Sep-13 1:10
larsp77727-Sep-13 1:10 
GeneralRe: Problem using DataContractSerializer Pin
Member 424999727-Sep-13 2:00
Member 424999727-Sep-13 2:00 
GeneralRe: Problem using DataContractSerializer Pin
larsp77727-Sep-13 2:02
larsp77727-Sep-13 2:02 
QuestionUnable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'System.Windows.Forms.HtmlDocument'. Pin
Member 881108925-Sep-13 1:02
Member 881108925-Sep-13 1:02 
AnswerRe: Unable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'System.Windows.Forms.HtmlDocument'. Pin
Richard MacCutchan25-Sep-13 1:45
mveRichard MacCutchan25-Sep-13 1:45 
AnswerRe: Unable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'System.Windows.Forms.HtmlDocument'. Pin
BillWoodruff25-Sep-13 3:09
professionalBillWoodruff25-Sep-13 3:09 
GeneralRe: Unable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'System.Windows.Forms.HtmlDocument'. Pin
Member 881108925-Sep-13 5:00
Member 881108925-Sep-13 5:00 
GeneralRe: Unable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'System.Windows.Forms.HtmlDocument'. Pin
TnTinMn25-Sep-13 16:43
TnTinMn25-Sep-13 16:43 
GeneralRe: Unable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'System.Windows.Forms.HtmlDocument'. Pin
BillWoodruff26-Sep-13 8:01
professionalBillWoodruff26-Sep-13 8:01 
GeneralRe: Unable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'System.Windows.Forms.HtmlDocument'. Pin
TnTinMn26-Sep-13 15:29
TnTinMn26-Sep-13 15:29 
QuestionChessboard UI Pin
DeFles24-Sep-13 23:40
DeFles24-Sep-13 23:40 
AnswerRe: Chessboard UI Pin
Abhinav S24-Sep-13 23:45
Abhinav S24-Sep-13 23:45 
QuestionOutOfMemoryException Pin
ptvce24-Sep-13 21:04
ptvce24-Sep-13 21:04 
SuggestionRe: OutOfMemoryException Pin
Richard Deeming25-Sep-13 1:38
mveRichard Deeming25-Sep-13 1:38 

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.