Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack client on a Xamarin.iOS project

I am trying to use the ServiceStack clients on a Xamarin iOS project and when debugging it I have the following exception:

“System.ArgumentException: PclExport.Instance needs to be initialized”.

The code that produces the exception is the following:

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 am using ServiceStack.Interfaces, ServiceStack.Client.Pcl and ServiceStack.Text.Pcl all having version 4.0.34. Additionally I referenced Newtonsoft.Json at version 6.0.7.

After some research I realized that the PCL provider for iOS is not registered automatically, so I added “IosPclExportClient.Configure();” before instantiating the new Json Service Client and a I referenced ServiceStack.Pcl.iOS.dll at version 4.0.0.0.

The result is the following error: “Cannot include both 'monotouch.dll' and 'Xamarin.iOS.dll' in the same Xamarin.iOS project - 'Xamarin.iOS.dll' is referenced explicitly, while 'monotouch.dll' is referenced by 'ServiceStack.Pcl.iOS, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'.”

Is there is any suggestion of resolving this problem?

Thank you in advance

like image 263
George Avatar asked Dec 30 '14 07:12

George


1 Answers

You need to call IosPclExportClient.Configure(); when you application starts to initialise 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 a I referenced ServiceStack.Pcl.iOS.dll at version 4.0.0.0.

The PCL specific NuGet packages of ServiceStack are no longer maintained, as they have been merged into the main NuGet package using specific profile.

You should only be including the ServiceStack.Client package in your project. So remove all references to ServiceStack in your project, clean the build, and add just ServiceStack.Client.

If you reference ServiceStack.Client.Pcl was well as ServiceStack.Client you will get a conflict.

like image 157
Scott Avatar answered Oct 18 '22 05:10

Scott