Click here to Skip to main content
15,900,110 members
Home / Discussions / C#
   

C#

 
AnswerRe: Directshow problem Pin
TheyCallMeMrJames16-Jun-10 4:37
TheyCallMeMrJames16-Jun-10 4:37 
GeneralRe: Directshow problem Pin
Eduard Keilholz16-Jun-10 4:51
Eduard Keilholz16-Jun-10 4:51 
QuestionOwnerDrawn TabControl behaving differently in Design Mode [modified] [solved] Pin
TheFoZ16-Jun-10 3:11
TheFoZ16-Jun-10 3:11 
AnswerRe: OwnerDrawn TabControl behaving differently in Design Mode Pin
Johnny J.16-Jun-10 3:49
professionalJohnny J.16-Jun-10 3:49 
GeneralRe: OwnerDrawn TabControl behaving differently in Design Mode Pin
TheFoZ16-Jun-10 4:32
TheFoZ16-Jun-10 4:32 
AnswerRe: OwnerDrawn TabControl behaving differently in Design Mode - solution Pin
TheFoZ16-Jun-10 5:51
TheFoZ16-Jun-10 5:51 
Questioncombobox inside datagridview Pin
Rajee Maharjan16-Jun-10 1:40
Rajee Maharjan16-Jun-10 1:40 
QuestionSerializing a Collection - Inheritance problem Pin
lukeer16-Jun-10 1:39
lukeer16-Jun-10 1:39 
Hi Experts,

I'm trying to serialize a collection
    using (System.IO.MemoryStream saveStream = new System.IO.MemoryStream())
    {
/*Ex*/  System.Xml.Serialization.XmlSerializer saveSerializer = new System.Xml.Serialization.XmlSerializer(typeof(MyFineCollection));
        saveSerializer.Serialize(saveStream, _manyObjects);
    }
The collection contains objects of following types
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Test_Xml
{
    public class MyFantasticBaseClass
    {
        private int _id = 0;

        public MyFantasticBaseClass(int id)
        {
            this._id = id;
        }

        public int Id
        {
            get { return (_id); }
        }
    }


    public class FirstDerivedClass : MyFantasticBaseClass
    {
        private bool _isReallyUseful = true;

        public bool IsReallyUseful
        {
            get { return (_isReallyUseful); }
            set { _isReallyUseful = value; }
        }
    }


    public class SecondDerivedClass : MyFantasticBaseClass
    {
        private double _zoom = 1.0;
        private MyFantasticBaseClass _linkedElement = null;

        public double Zoom
        {
            get { return (_zoom); }
            set { _zoom = value; }
        }

        public MyFantasticBaseClass LinkedElement
        {
            get { return (_linkedElement); }
            set { _linkedElement = value; }
        }
    }


    public class MyFineCollection:ICollection<MyFantasticBaseClass>
    {
        List<MyFantasticBaseClass> _innerList = new List<MyFantasticBaseClass>();

        // ICollection implementation details
    }
}
Now, when collection contains an instance of one of the child classes, the line marked with "/*Ex*/" throws an InvalidOperationException with inner NullReferenceException.

How can I serialize the collection including all objects derived from MyFantasticBaseClass?

Ciao,


luker

AnswerRe: Serializing a Collection - Inheritance problem Pin
riced16-Jun-10 3:05
riced16-Jun-10 3:05 
AnswerRe: Serializing a Collection - Inheritance problem Pin
Pete O'Hanlon16-Jun-10 3:07
mvePete O'Hanlon16-Jun-10 3:07 
GeneralRe: Serializing a Collection - Inheritance problem Pin
lukeer16-Jun-10 4:09
lukeer16-Jun-10 4:09 
AnswerRe: Serializing a Collection - Inheritance problem Pin
Rob Graham19-Jun-10 3:21
Rob Graham19-Jun-10 3:21 
QuestionPrinting Quality Image Vs Text Pin
Anubhava Dimri16-Jun-10 0:05
Anubhava Dimri16-Jun-10 0:05 
AnswerRe: Printing Quality Image Vs Text Pin
Nuri Ismail16-Jun-10 0:26
Nuri Ismail16-Jun-10 0:26 
GeneralRe: Printing Quality Image Vs Text Pin
Anubhava Dimri17-Jun-10 20:09
Anubhava Dimri17-Jun-10 20:09 
AnswerRe: Printing Quality Image Vs Text Pin
Luc Pattyn16-Jun-10 2:25
sitebuilderLuc Pattyn16-Jun-10 2:25 
QuestionWhich is better and why? Pin
Hum Dum15-Jun-10 22:53
Hum Dum15-Jun-10 22:53 
AnswerRe: Which is better and why? Pin
Bigdeak15-Jun-10 23:22
Bigdeak15-Jun-10 23:22 
GeneralRe: Which is better and why? Pin
Hum Dum16-Jun-10 0:31
Hum Dum16-Jun-10 0:31 
AnswerRe: Which is better and why? Pin
Abhinav S16-Jun-10 0:36
Abhinav S16-Jun-10 0:36 
AnswerRe: Which is better and why? Pin
Eddy Vluggen16-Jun-10 1:15
professionalEddy Vluggen16-Jun-10 1:15 
AnswerRe: Which is better and why? Pin
PIEBALDconsult16-Jun-10 3:06
mvePIEBALDconsult16-Jun-10 3:06 
AnswerNeither approach is appropriate Pin
Ennis Ray Lynch, Jr.16-Jun-10 6:14
Ennis Ray Lynch, Jr.16-Jun-10 6:14 
GeneralRe: Neither approach is appropriate Pin
Hum Dum16-Jun-10 17:49
Hum Dum16-Jun-10 17:49 
GeneralRe: Neither approach is appropriate Pin
Ennis Ray Lynch, Jr.17-Jun-10 5:19
Ennis Ray Lynch, Jr.17-Jun-10 5:19 

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.