ServiceStack Client in Xamarin.iOS Project

I'm trying to use ServiceStack clients in a XAMAIN iOS project, and when debugging it, I have the following exception:

"System.ArgumentException: PclExport.Instance must be initialized."

The code that throws the exception is as follows:

try { string strReadParam = this.xmlParser.GetString("SyncUrl"); CommonStatic.SyncWSUrl = strReadParam; var client = new JsonServiceClient(CommonStatic.SyncWSUrl); client.Timeout = new TimeSpan(0, 0, 0, 5, 0); var response = client.Get(new mSalesCheckConnectionRequest { DBSource = CommonStatic.DBSource, DBSourceInstance = CommonStatic.DBSourceInstance, DBName = CommonStatic.DBName, DBUsername = CommonStatic.DBUsername, DBPassword = CommonStatic.DBPassword }); return; } catch (System.Net.WebException wex) { } 

I use ServiceStack.Interfaces, ServiceStack.Client.Pcl and ServiceStack.Text.Pcl, having version 4.0.34. In addition, I referenced Newtonsoft.Json in version 6.0.7.

After some research, I realized that the PCL provider for iOS was not automatically registered, so I added "IosPclExportClient.Configure ();" before creating a new Json service client and I referenced ServiceStack.Pcl.iOS.dll in version 4.0.0.0.

As a result, the following error occurs: "You cannot include both" monotouch.dll "and" Xamarin.iOS.dll "in the same Xamarin.iOS project -" Xamarin.iOS.dll "is explicitly specified, and" monotouch.dll "is referenced on "ServiceStack.Pcl". iOS, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = null '. "

Are there any suggestions to solve this problem?

Thank you in advance

+6
source share
1 answer

You need to call IosPclExportClient.Configure(); when the application starts initializing the PCL export client before use in iOS applications.

So, in your Main method:

 static void Main (string[] args) { // Configure ServiceStack Client IosPclExportClient.Configure(); // Set AppDelegate UIApplication.Main (args, null, "AppDelegate"); } 

and I referenced ServiceStack.Pcl.iOS.dll in version 4.0.0.0.

PCL-specific NuGet ServiceStack packages are no longer supported as they have been bundled into the main NuGet package using a specific profile.

should << β†’ include ServiceStack.Client in your project. Therefore, remove all references to ServiceStack in your project, clean the assembly and add only ServiceStack.Client .

If you reference ServiceStack.Client.Pcl , it’s good, as ServiceStack.Client , you will get a conflict.

+7
source

Source: https://habr.com/ru/post/980290/


All Articles