Type Initialization Exception

Hello,

I am developing a Xamarin.Forms application. After I upgraded to Xcode 10.2, It triggers the following exception every time a request is sent to server.

The type initializer for ‘ServiceStack.Text.Json.JsonReader`1’ threw an exception.

at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
at ServiceStack.Text.JsonSerializer.DeserializeFromString[T] (System.String value) [0x00012] in <6938b7c647be433bbd75df27e0fee17e>:0
at ServiceStack.Text.JsonSerializer.DeserializeFromStream[T] (System.IO.Stream stream) [0x00012] in <6938b7c647be433bbd75df27e0fee17e>:0
at ServiceStack.Serialization.JsonDataContractSerializer.DeserializeFromStream[T] (System.IO.Stream stream) [0x0003a] in <52aab4d925264d8287f22de0eaacfd67>:0
at ServiceStack.JsonServiceClient.DeserializeFromStream[T] (System.IO.Stream stream) [0x00000] in <52aab4d925264d8287f22de0eaacfd67>:0
at ServiceStack.ServiceClientBase.GetResponse[TResponse] (System.Net.WebResponse webResponse) [0x000e8] in <52aab4d925264d8287f22de0eaacfd67>:0
at ServiceStack.ServiceClientBase.Send[TResponse] (System.String httpMethod, System.String relativeOrAbsoluteUrl, System.Object request) [0x0012c] in <52aab4d925264d8287f22de0eaacfd67>:0
at ServiceStack.ServiceClientBase.Get[TResponse] (ServiceStack.IReturn`1[T] requestDto) [0x00012] in <52aab4d925264d8287f22de0eaacfd67>:0

However, all services work perfectly when testing through Swagger UI.

Any idea about this issue?

Thanks in advance.

I’m assuming that’s going to be a bug in Mono not handling changes in latest Xcode library.

If there’s a new Xamarin/Mono versions I’d try upgrading to it.

Otherwise I can’t tell from the StackTrace which doesn’t show why it failed but as it failed when trying to read from the stream it could be due to App Transport Security being enabled by default. You can try opting out of ATS.

Thank you mythz. The “opting out of ATS” solution doesn’t quite fit my application… I also tried downgrading the Xcode to 10.1, but it’s not working anymore. There should be some system changes during previous upgrading.

It’s kind of clumsy, but I re-installed my Mac OS, together with VS2017 and Xcode 10.1. Now everything is back to normal. I will try upgrading later when the latest Xcode is stable enough…

1 Like