Start a new topic

Xamarin Collection members cause System.NotSupportedException "Don't know about..."

I have a very simple problem I can't figure out. 

 When I try to create a DataStore that has an object with a collection as a child, I get System.NotSupportedException: 'Don't know about System.Collections.Generic.List`1[System.Int32]'. This error comes from SQLite.NET. 

https://forums.xamarin.com/discussion/2546/create-table-in-xamarin-throws-exception-because-of-generic-list 


The actual type of the collection - List, Array, IEnumerable - and the type of the item in the collection - int, string, a class - doesn't seem to matter. It just doesn't like collections.


I couldn't find any .NET documentation on this, and I couldn't find anything in the forums - the only other reference I found had the solution "I stopped using Kinvey"

https://support.kinvey.com/support/discussions/topics/12000016274


Here's a simple program that can replicate the error.

using System;
using System.Collections.Generic;
using Kinvey;
using Newtonsoft.Json;

namespace KinveyCollectionTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var builder = new Client.Builder("appKey", "appSecret")
                //    .SetFilePath(filePath) // optional
                .setLogger(Console.WriteLine); //optional
            Client kinveyClient = builder.Build();

            //This works
            DataStore<Simple> simpleCollection = DataStore<Simple>.Collection("Simple", DataStoreType.AUTO, kinveyClient);

            // This doesn't work
            DataStore<ComplexEntity> complexCollection = DataStore<ComplexEntity>.Collection("Complex", DataStoreType.AUTO, kinveyClient);
            
            Console.Out.WriteLine("Press any key to quit");
            Console.ReadKey();
        }
    }

    [JsonObject(MemberSerialization = MemberSerialization.OptIn)]
    internal class ComplexEntity
    {
        [JsonProperty("Integers")]
        public List<int> Integers { get; set; }
    }

    [JsonObject(MemberSerialization = MemberSerialization.OptIn)]
    public class Simple : Entity
    {
        [JsonProperty("Integer")]
        public int Integer { get; set; }

        [JsonProperty("String")]
        public string Str { get; set; }
    }
}

  





Windows 10

.NET Framework 4.8

Development Environment: VS 2019

Kinvey SDK Version: 4.3.2


I should note that changing from AUTO to NETWORK data store type fixes this.

Hello Stephen,


The reported issue is most likely related to some specifics in the complex objects usage and limitations of SQLite. Classes for complex objects must have [DataContract] and [DataMember] attributes as shown in the example below. Additionally, SQLite does not support generic lists by default - the workaround there is that generic lists can be included in classes, which are complex objects. Changing from AUTO to NETWORK data store type resolves the issue because no data is stored on the device, which means that SQLite is no longer used.


Here is a basic example of the points mentioned above:

 

[JsonObject(MemberSerialization.OptIn)]
public class Route : Entity
{
	 [Kinvey.Preserve, JsonProperty("StopList "), Column("StopList")]
        public StopList StopList { get; set; }
}

[JsonObject(MemberSerialization.OptIn)]
[DataContract]
public class StopList : Entity
{
       [Kinvey.Preserve, JsonProperty("stops")]
       [DataMember]
       public List<string> Stops { get; set; } = new List<string>();
}

I hope this is of any help. Please, let me know if you require further assistance.


Regards,

Garo

Thanks very much. For anyone reading this, you need to explicitly reference the System.Runtime.Serialization assembly to get access to DataContract and DataMember.

Login or Signup to post a comment