Which data types can be used when communicating with an App Service in UWP

3

I have created an UWP app with an app service and communication between those are done using value sets in an AppServiceConnection. I can however not find out what types of data that are supported in the value sets that are transferred.

Here is some test code

class MyClass { public int Prop1 { get; set; } }
var data = new ValueSet();
var stringlist = new List<string>() {"a string"};

// This does not work
// data.Add("data", new MyClass() { Prop1 = 1});

// This does not work
// data.Add("data", stringlist);

// This works fine!!
data.Add("data", stringlist.ToArray());

When using a not supported data type I get the error below, thus it is pretty clear that it is not supported. I can however not find any documentation around this and I cannot find out exactly what is supposed to be supported.

Unhandled Exception: System.Exception: Data of this type is not supported.
(Exception from HRESULT: 0x8007065E)

A second question; is it possible to create a class so that I can use it in the value sets?

c#
uwp
asked on Stack Overflow Oct 11, 2017 by Jonas Pegerfalk

1 Answer

1

You can include all types that can be serialized. So any data type that has a default constructor that takes in 0 arguments and the fields inside them are also serializable or the ones that aren't serializable are DataAnotated as [JsonIgnore] are acceptable.

That being said, it's a safe bet to send in serialized data to the values.

To do so, you can use NewtonSoft nugget for Json serialization from the nugget package store and when you have the data that you need to send (if it's not a string) you serialize the object and then send it and when you receive it you'll get a serialized object that you can deserialize to get the data.

answered on Stack Overflow Oct 11, 2017 by iam.Carrot

User contributions licensed under CC BY-SA 3.0