Search code examples
visual-studioxamarinxamarin.iostask-parallel-libraryportable-class-library

System.PlatformNotSupportedException when making calls from iPhone client


I'm trying to have Tasks working under Visual Studio 2012 with MonoTouch. I'm using ALPHA channel and have the latest releases installed.

There are 3 projects in solution: 1. PCL (158 target platforms) with async methods 2. Touch 3. Android

This code compiles, could be deployed and executed. But when I make calls from iPhone client:

var asyncResult = await MyClass.DoStuff();
Console.WriteLine("doing stuff completed: " + asyncResult);

I get the following result:

System.PlatformNotSupportedException: This platform is not supported

at await part of code. When I write it with Task.ContinueWith - same result.

What is interesting is doesn't work only under Visual Studio + MonoTouch. All other configurations launches this code correctly (WIN+VS+Android, WIN+VS+Android, MAC+XS+iOS, MAC+XS+Android)

Versions of SDK are synchronized with the latest ALPHA release.

Exception details: Unhandled Exception:

System.PlatformNotSupportedException: This platform is not supported.
2013-07-25 11:45:32.384 iPhone[1817:907] Unhandled managed exception: This platform is not supported. (System.PlatformNotSupportedException)
  at System.ExecutionContextLightup.Run (System.ExecutionContextLightup executionContext, System.Action`1 callback, System.Object state) [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00000] in <filename unknown>:0 
  at Microsoft.Runtime.CompilerServices.TaskAwaiter+<>c__DisplayClassa.<OnCompletedInternal>b__1 (System.Object state) [0x00000] in <filename unknown>:0 
  at MonoTouch.UIKit.UIKitSynchronizationContext+<Post>c__AnonStorey52.<>m__4E () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIKitSynchronizationContext.cs:24 
  at MonoTouch.Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Developer/MonoTouch/Source/monotouch/src/shared/Foundation/NSAction.cs:87 
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at
 MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 
  at iPhone.Application.Main (System.String[] args) [0x00001] in c:\Sources\Local\PCL_XN\iPhone\Main.cs:17 
The program 'Mono' has exited with code 0 (0x0).
The program '[6760] iPhone.vshost.exe: Managed (v4.0.30319)' has exited with code -1 (0xffffffff).

Solution

  • A bit of a late reply, but in case anyone is still running into this, it looks like one workaround is to add --nolinkaway --linkskip=mscorlib under "Project Options -> iOS Build -> Additional mtouch arguments" for the main application project.

    Without this, the linker removes something from mscorlib that the Microsoft.Bcl package requires for its compatibility checks.

    Bug filed here: https://bugzilla.xamarin.com/show_bug.cgi?id=15290