Dragos
Dragos

Reputation: 296

Xamarin.Forms: Call to a API using ServiceStack throws exception

I have a local service made with ServiceStack and I want to call a method from my Xamarin.Forms application:

  ServiceStack.JsonServiceClient sc;
  sc = new ServiceStack.JsonServiceClient("http://api.sportsstars.local/");

When the debugger reaches the second line, it throws this exception:

System.TypeInitializationException: An exception was thrown by the type initializer for ServiceStack.ServiceClientBase

Any ideas what could it be?

Upvotes: 0

Views: 348

Answers (2)

Dragos
Dragos

Reputation: 296

I have found out how to avoid the exception. I've put the code in the Droid project and used a DependencyService to call the method from my PCL project. My problem was for Android. If you get the problem for IOS, the other answer may help you.

Upvotes: 0

mythz
mythz

Reputation: 143319

Have you initialized the PCL Client? You can configure it by adding:

ServiceStack.IosPclExportClient.Configure();

To your application on StartUp.

Upvotes: 1

Related Questions