Hiya,
I'm trying to use the TRIMServiceAPI in a .net framework application to create locations via the trimclient Post method...
public TrimResults CreateLocation(string regno, string honorific, string surname, string givenNames, string birtdate) { try { Location newLocation = new Location { TypeOfLocation = LocationType.Person, Surname = surname, GivenNames = givenNames, Honorific = honorific, DateOfBirth = (TrimDateTime)DateTime.Parse(birtdate), Notes = TrimModel.UtilityMessage, Initials = GetInitials(givenNames, surname), IdNumber = regno }; newLocation.SetCustomField("RegistrationNumber", regno); var response = _trimClient.Post(newLocation); Console.WriteLine("OK!"); ...
The post is successful, and I can see the location created in the Content Manager client, including the custom field value for RegistrationNumber,
but it the Post throws an exception before i can read the response...
System.NotSupportedException: TrimStringProperty is not an allowed Runtime Type. Whitelist Type with [Serializable], [RuntimeSerializable], [DataContract] or IRuntimeSerializable, see: docs.servicestack.net/json-format
at ServiceStack.Text.Common.JsWriter.AssertAllowedRuntimeType(Type type) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Common/JsWriter.cs:line 216
at ServiceStack.Text.Common.DeserializeType`1.ExtractType(ReadOnlySpan`1 strType) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Common/DeserializeType.cs:line 130
at ServiceStack.Text.Common.DeserializeType`1.ParseAbstractType[T](ReadOnlySpan`1 value) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Common/DeserializeType.cs:line 148
at ServiceStack.Text.Json.JsonReader`1.Parse(ReadOnlySpan`1 value) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Json/JsonReader.Generic.cs:line 111
at ServiceStack.Text.Json.JsonReader`1.Parse(String value) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Json/JsonReader.Generic.cs:line 84
at ServiceStack.Text.JsonSerializer.DeserializeFromString[T](String value) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/JsonSerializer.cs:line 47
at ServiceStack.Text.JsonExtensions.Get[T](Dictionary`2 map, String key, T defaultValue) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/JsonObject.cs:line 25
at HP.HPTRIM.Service.Client.TrimClient.ToDictionary[T,P](String json)
at HP.HPTRIM.Service.Client.TrimClient.<>c.<FriendlyDictionaries>b__0_8(String val)
at ServiceStack.Text.JsConfig`1.ParseFn(ITypeSerializer serializer, String str) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/JsConfig.cs:line 1001
at ServiceStack.Text.Common.JsReader`1.<>c__4`1.<GetCoreParseStringSpanFn>b__4_0(ReadOnlySpan`1 value) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Common/JsReader.cs:line 48
at ServiceStack.Text.Common.DeserializeTypeRefJson.StringToType(ReadOnlySpan`1 strType, TypeConfig typeConfig, EmptyCtorDelegate ctorFn, KeyValuePair`2[] typeAccessors) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Common/DeserializeTypeRefJson.cs:line 149
at ServiceStack.Text.Common.DeserializeType`1.StringToTypeContext.DeserializeJson(ReadOnlySpan`1 value) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Common/DeserializeType.cs:line 58
at ServiceStack.Text.Common.DeserializeListWithElements`2.ParseGenericList(ReadOnlySpan`1 value, Type createListType, ParseStringSpanDelegate parseFn) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Common/DeserializeListWithElements.cs:line 194
at ServiceStack.Text.Common.DeserializeList`2.<>c__DisplayClass7_0.<GetParseStringSpanFn>b__0(ReadOnlySpan`1 value) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Common/DeserializeListWithElements.cs:line 284
at ServiceStack.Text.Common.DeserializeTypeRefJson.StringToType(ReadOnlySpan`1 strType, TypeConfig typeConfig, EmptyCtorDelegate ctorFn, KeyValuePair`2[] typeAccessors) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Common/DeserializeTypeRefJson.cs:line 149
at ServiceStack.Text.Common.DeserializeType`1.StringToTypeContext.DeserializeJson(ReadOnlySpan`1 value) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Common/DeserializeType.cs:line 58
at ServiceStack.Text.Json.JsonReader.<>c__DisplayClass3_0.<GetParseSpanFn>b__0(ReadOnlySpan`1 v) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/Json/JsonReader.Generic.cs:line 20
at ServiceStack.Text.JsonSerializer.DeserializeFromSpan(Type type, ReadOnlySpan`1 value) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/JsonSerializer.cs:line 62
at ServiceStack.Text.DefaultMemory.Deserialize(MemoryStream ms, Boolean fromPool, Type type, DeserializeStringSpanDelegate deserializer) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/DefaultMemory.cs:line 547
at ServiceStack.Text.DefaultMemory.Deserialize(Stream stream, Type type, DeserializeStringSpanDelegate deserializer) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/DefaultMemory.cs:line 523
at ServiceStack.Text.JsonSerializer.DeserializeFromStream[T](Stream stream) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/JsonSerializer.cs:line 210
at ServiceStack.Serialization.JsonDataContractSerializer.DeserializeFromStream[T](Stream stream) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/Serialization/JsonDataContractSerializer.Deserialize.cs:line 60
at ServiceStack.JsonServiceClient.DeserializeFromStream[T](Stream stream) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/JsonServiceClient.cs:line 29
at ServiceStack.ServiceClientBase.GetResponse[TResponse](WebResponse webRes) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/ServiceClientBase.cs:line 2073
at ServiceStack.ServiceClientBase.Send[TResponse](String httpMethod, String relativeOrAbsoluteUrl, Object request) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/ServiceClientBase.cs:line 1413
at ServiceStack.ServiceClientBase.Post[TResponse](IReturn`1 requestDto) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/ServiceClientBase.cs:line 1558
at HP.HPTRIM.Service.Client.TrimClient.Post[TResponse](IReturn`1 request)
When I remove the SetCustomField line of code, then the post works OK without the exception!
Am i doing something wrong? I need the response, to pass on the Uri, and i also need to set the RegistrationNumber field value on create.
I think the error is misleading because, as far as I can tell, TrimStringProperty inherits ITrimProperty which does have the [DataContract] decoration.
Help!