ServiceStack / Issues

Issue Tracker for the commercial versions of ServiceStack
11 stars 6 forks source link

ServiceStack and Xamarin.Forms PCL project #242

Closed anarefin closed 9 years ago

anarefin commented 9 years ago

I have a Xamarin.Forms portable solution, in a class in the PCL project I have this:

protected ServiceStack.JsonServiceClient sc;

in the constructor I have:

sc = new ServiceStack.JsonServiceClient(url);

I run the Android projet and when the execution reaches that code I am getting the error "PclExport.Instance needs to be initialized", what am I missing?

Thanks,

Complete error:

[MonoDroid] UNHANDLED EXCEPTION: [MonoDroid] System.TypeInitializationException: An exception was thrown by the type initializer for ServiceStack.ServiceClientBase ---> System.TypeInitializationException: An exception was thrown by the type initializer for ServiceStack.Text.Env ---> System.ArgumentException: PclExport.Instance needs to be initialized [MonoDroid] at ServiceStack.Text.Env..cctor () [0x00000] in <filename unknown>:0 [MonoDroid] --- End of inner exception stack trace --- [MonoDroid] at ServiceStack.ServiceClientBase..cctor () [0x00000] in

:0 [MonoDroid] --- End of inner exception stack trace --- [MonoDroid] at ServiceStack.JsonServiceClient..ctor (System.String baseUri) [0x00000] in :0 [MonoDroid] at Scanpack.net.SAL.WebConnector..ctor (System.String factoryToken) [0x00000] in :0 [MonoDroid] at Scanpack.net.BL.ServiceManager..ctor () [0x00000] in :0 [MonoDroid] at Scanpack.net.PrintLabels..ctor () [0x00000] in :0 [MonoDroid] at Scanpack.net.MainScreen+ctor>b__9>d__13.MoveNext () [0x00000] in :0 [mono] [mono] Unhandled Exception: [mono] System.TypeInitializationException: An exception was thrown by the type initializer for ServiceStack.ServiceClientBase ---> System.TypeInitializationException: An exception was thrown by the type initializer for ServiceStack.Text.Env ---> System.ArgumentException: PclExport.Instance needs to be initialized [mono] at ServiceStack.Text.Env..cctor () [0x00000] in :0 [mono] --- End of inner exception stack trace --- [mono] at ServiceStack.ServiceClientBase..cctor () [0x00000] in :0 [mono] --- End of inner exception stack trace --- [mono] at ServiceStack.JsonServiceClient..ctor (System.String baseUri) [0x00000] in :0 [mono] at Scanpack.net.SAL.WebConnector..ctor (System.String factoryToken) [0x00000] in :0 [mono] at Scanpack.net.BL.ServiceManager..ctor () [0x00000] in :0 [mono] at Scanpack.net.PrintLabels..ctor () [0x00000] in :0 [mono] at Scanpack.net.MainScreen+ctor>b__9>d__13.MoveNext () [0x00000] in :0 [mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for ServiceStack.ServiceClientBase ---> System.TypeInitializationException: An exception was thrown by the type initializer for ServiceStack.Text.Env ---> System.ArgumentException: PclExport.Instance needs to be initialized [mono-rt] at ServiceStack.Text.Env..cctor () [0x00000] in :0 [mono-rt] --- End of inner exception stack trace --- [mono-rt] at ServiceStack.ServiceClientBase..cctor () [0x00000] in :0 [mono-rt] --- End of inner exception stack trace --- [mono-rt] at ServiceStack.JsonServiceClient..ctor (System.String baseUri) [0x00000] in :0 [mono-rt] at Scanpack.net.SAL.WebConnector..ctor (System.String factoryToken) [0x00000] in :0 [mono-rt] at Scanpack.net.BL.ServiceManager..ctor () [0x00000] in :0 [mono-rt] at Scanpack.net.PrintLabels..ctor () [0x00000] in :0 [mono-rt] at Scanpack.net.MainScreen+ctor>b__9>d__13.MoveNext () [0x00000] in :0
mythz commented 9 years ago

You can initialize the PCL Client for iOS with:

IosPclExportClient.Configure();

For Android it would be:

AndroidPclExportClient.Configure()

But it's normally implicitly inferred for Android.

anarefin commented 9 years ago

Where I will initialize this IosPclExportClient.Configure(); ?

mythz commented 9 years ago

Once, at the start of your program.

anarefin commented 9 years ago

Solved! Thanks a lot!