I would like to serialize the list of derived objects to json and to deserialize. Serialization works fine, the deserialize fails to convert the objects to derived class objects, all objects are deserialized to base class objects and lose members that belong to the derived class.
I have base class AutoEvent, and derived classes MouseClickEvent and ClickImageEvent, so once
i deserialize to List all objects are of type AutoEvent. How can i deserialize so that i can convert each object to the derived class object?

```
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Web.Script.Serialization;

namespace AutoEvent
{            
    public class AutoEvent
    {
        public string Name { get; set; }
        public int DelayMs { get; set; }
        public AutoEvent(string name, int delayMs)
        {
            Name = name;
            DelayMs = delayMs;
        }
        public AutoEvent() { }
    }

    public class MouseClickEvent : AutoEvent
    {
        public Rectangle RectArea { get; set; }
        public bool IsDoubleClick { get; set; }
        public MouseClickEvent(string name, int delayMs, Rectangle rectArea, bool isDoubleClick) : base(name, delayMs)
        {
            RectArea = rectArea;
            IsDoubleClick = isDoubleClick;
        }
        public MouseClickEvent() { }

    }

    public class ClickImageEvent : AutoEvent
    {
        public List<string> ImgFiles { get; set; }
        public Rectangle SearchArea { get; set; }
        public double ImgTolerance { get; set; }
        public double ImgError { get; set; }
        public bool IsDoubleClick { get; set; }
        public ClickImageEvent(string name, int delayMs, Rectangle searchArea, bool isDoubleClick, double imgTol, double imgErr) : base(name, delayMs)
        {
            SearchArea = searchArea;
            IsDoubleClick = isDoubleClick;
            ImgTolerance = imgTol;
            ImgError = imgErr;
        }
        public ClickImageEvent() { }

    }

    class Program
    {
        static void Main(string[] args)
        {
            string path = @"c:/nenad/testSer.txt";
            List<AutoEvent> events = new List<AutoEvent>();
            MouseClickEvent clickEvent1 = new MouseClickEvent("mouse click1", 100, new Rectangle(20, 30, 15, 10), true);
            MouseClickEvent clickEvent2 = new MouseClickEvent("mouse click2", 15, new Rectangle(20, 45, 15, 10), true);
            ClickImageEvent imgclick1 = new ClickImageEvent("image click1", 15, new Rectangle(20, 45, 555, 150), false, 0.1, 0.05);
            ClickImageEvent imgclick2 = new ClickImageEvent("image click2", 125, new Rectangle(2220, 45, 5525, 150), false, 0.15, 0.25);
            events.Add(clickEvent1);
            events.Add(clickEvent2);
            events.Add(imgclick1);
            events.Add(imgclick2);

            JavaScriptSerializer ser = new JavaScriptSerializer();
            string json = ser.Serialize(events);
            if (!File.Exists(path))
            {
                using (var h = File.Create(path)) ;
            }

            File.WriteAllText(path, json);

            json = File.ReadAllText(path);
            events = ser.Deserialize<List<AutoEvent>>(json);
            MouseClickEvent event1 = (MouseClickEvent)events[0]; // fails at runtime to convert 
            ClickImageEvent event2 = (ClickImageEvent)events[2]; // fails at runtime to convert 
        }
    }
}

```