I have a Queue of an abstract class KVP. I queue 2 different objects which inherit from KVP. Everything works fine when I serialize the queue, but since KVP cannot be constructed it fails on deserialization.

If it was a single non generic object I could deserialize as dynamic, but I'm not sure how to deserialize a queue that could hold both events and IDs.

Sample code:

```
public virtual async Task<bool> LoadFromFile(string FileName, bool addToExistingQueue,bool DeleteFileAfterLoad = true)
        {
            try
            {
                IFile File = await PCLStorage.FileSystem.Current.LocalStorage.GetFileAsync(FileName);
                var serializedText = await File.ReadAllTextAsync();
                var mQueue = JsonConvert.DeserializeObject<Queue<T>>(serializedText,jss);
                if (!addToExistingQueue)
                {
                    _queue = new ConcurrentQueue<T>();
                }
                while (mQueue.Count > 0)
                {
                    _queue.Enqueue(mQueue.Dequeue());
                }

                if (DeleteFileAfterLoad)
                {
                    await File.DeleteAsync();
                }
                return true;

            }
            catch (Exception ex)
            {
                Debug.WriteLine("Could not load File. Exception Message: " + ex.Message);
                return false;
            }

        }
        public virtual async Task<bool> WriteToFile(string FileName)
        {
            try
            {
                Debug.WriteLine("Writing File: " + FileName);
                var File = await FileSystem.Current.LocalStorage.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting);
                var serializedText = JsonConvert.SerializeObject(_queue.ToList(),jss);
                await File.WriteAllTextAsync(serializedText);
                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Could not write File with exception message: " + ex.Message);
                return false;
            }

        }

```
['https://Stackoverflow.com/questions/29214407', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1104177/']
You could 

1. Enable [TypeNameHandling](http://www.newtonsoft.com/json/help/html/P_Newtonsoft_Json_JsonSerializerSettings_TypeNameHandling.htm) (in both serialization and deserialization):

```
    var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto };
    var serializedText= JsonConvert.SerializeObject(mQueue, settings);

```

And then later

```
    var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto };
    var mQueue = JsonConvert.DeserializeObject<Queue<T>>(serializedText, settings);

```

This adds an extra `"$type"` property to your polymorphic classes, as is described [here](http://james.newtonking.com/archive/2010/08/13/json-net-3-5-release-8-3-5-final). 

Before choosing this solution, for a discussion of possible security concerns using `TypeNameHandling`, see [TypeNameHandling caution in Newtonsoft Json](https://stackoverflow.com/q/39565954/3744182) and [How to configure Json.NET to create a vulnerable web API](https://www.alphabot.com/security/blog/2017/net/How-to-configure-Json.NET-to-create-a-vulnerable-web-API.html).
2. Write a custom converter that looks at the actual properties and chooses which derived class to use, as is discussed here: [Deserializing polymorphic json classes without type information using json.net](https://stackoverflow.com/questions/19307752/deserializing-polymorphic-json-classes-without-type-information-using-json-net). This avoids the need for the extra `"$type"` property.
This should work if you use the following setting in the JSON.NET serialiser settings:

```
var settings = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.Auto};

```

This will encode the object type into the JSON stream, which will help the deserializer determined the specific object type to construct during de-serialization.