I have run into problems saving documents with Properties that are Interfaces' I am receiving this error.
 Could not create an instance of type GTA__Tests.ItemTests.IMyCommand. Type is an interface or abstract class and cannot be instantiated.
My Interface:
public interface IMyCommand
{
   [JsonProperty(PropertyName = "$type")]
   string CommandType { get; } 
}
My implementation:
public class MyCommand1 : IMyCommand
{
    [JsonProperty("$type")]
    public string CommandType => nameof(MyCommand1);
}
public class MyCommand2 : IMyCommand
{
    [JsonProperty("$type")]
    public string CommandType => nameof(MyCommand2);
}
//partition key is CompanyId
public class MyClass
{
     [JsonProperty("id")]
     public Guid Id { get; set; }
     public string CompanyId { get; set; }
     public List<IMyCommand> Commands { get; set; }
     public MyClass(string partitionKey)
     {
         CompanyId = partitionKey;
     }
}
My test code: Using NUnit
//Using cosmosdb .net sdk v3
public class Item_Tests
{
    private string url;
    private string key;
    private string dbName;
    private string containerName;
    private string partitionKey = "Test";
    CosmosClient client;
    Container db;
   [SetUp]
    public void SetUp()
    {
        var config = Config.GetConfig();
        url = config["CosmosLive:Url"];
        key = config["CosmosLive:Key"];
       dbName = config["CosmosLive:DbName"];
       containerName = config["CosmosLive:ContainerName"];
       client = new CosmosClient(url, key);
       db = client.GetContainer(dbName, containerName);
   }
    [Test]
    public async Task SaveAMyClassDocumentToCosmosDb_ReturnsOK()
   {
       var myclass = new MyClass(partitionKey)
       {
            Id = Guid.NewGuid(),
           Commands = new List<IMyCommand>
           {
                new MyCommand1(),
               new MyCommand2()
           }
       };
       var result = await db.UpsertItemAsync<MyClass>(myclass, new 
       PartitionKey(partitionKey));
       Assert.IsTrue(result.StatusCode is System.Net.HttpStatusCode.Created);
    }
This produces a Newtonsoft.Json.JsonSerializationException Where is my code wrong? This is the full excetion:
Newtonsoft.Json.JsonSerializationException: Could not create an instance of type GTA__Tests.ItemTests.IMyCommand. Type is an interface or abstract class and cannot be instantiated. Path 'Commands[0]', line 1, position 103.
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor`1 creator, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)
   at Microsoft.Azure.Cosmos.CosmosJsonDotNetSerializer.FromStream[T](Stream stream)
   at Microsoft.Azure.Cosmos.CosmosJsonSerializerWrapper.FromStream[T](Stream stream)
   at Microsoft.Azure.Cosmos.CosmosSerializerCore.FromStream[T](Stream stream)
   at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.ToObjectpublic[T](ResponseMessage responseMessage)
   at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.<CreateItemResponse>b__8_0[T](ResponseMessage cosmosResponseMessage)
   at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.ProcessMessage[T](ResponseMessage responseMessage, Func`2 createResponse)
   at Microsoft.Azure.Cosmos.CosmosResponseFactoryCore.CreateItemResponse[T](ResponseMessage responseMessage)
   at Microsoft.Azure.Cosmos.ContainerCore.UpsertItemAsync[T](T item, ITrace trace, Nullable`1 partitionKey, ItemRequestOptions requestOptions, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.ClientContextCore.RunWithDiagnosticsHelperAsync[TResult](ITrace trace, Func`2 task, Func`2 openTelemetry, String operationName, RequestOptions requestOptions)
   at Microsoft.Azure.Cosmos.ClientContextCore.OperationHelperWithRootTraceAsync[TResult](String operationName, RequestOptions requestOptions, Func`2 task, Func`2 openTelemetry, TraceComponent traceComponent, TraceLevel traceLevel)
   at GTA__Tests.ItemTests.Item_Tests.SaveAMyClassDocumentToCosmosDb_ReturnsOK() in C:\Users\pjsta\source\repos\GosportTaxiApp\GTA__Tests\ItemTests\Item_Tests.cs:line 142
 
    