Bug 13712 - Async System.TypeInitializationException
Summary: Async System.TypeInitializationException
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 6.3.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Martin Baulig
URL:
Depends on:
Blocks:
 
Reported: 2013-08-02 10:09 UTC by Mike James
Modified: 2016-11-11 09:35 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Mike James 2013-08-02 10:09:02 UTC
A customer has reported the following: 

I recently upgraded a cross platform application I'm writing to the latest version of Xamarin.iOS and Xamarin.Android so that I can make use of the async support you've added. The Android version works great, however, I'm receiving the error below in my iOS application. I should also note that I'm using MvvmCross and PCLs to help in code reuse, but as far as I can tell MvvmCross and PCLs aren't causing the issue. I've create a sample solution duplicating the error which can be found here: http://sdrv.ms/1b02djq System.TypeInitializationException: An exception was thrown by the type initializer for System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1

The thread '<No Name>' (0x1fe4) has exited with code 0 (0x0).


Unhandled Exception:

System.TypeInitializationException: An exception was thrown by the type initializer for System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1 ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Threading.Tasks.TaskScheduler ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: method return type is incompatible

at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure, Boolean allowClosed) [0x00078] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Delegate.cs:190 

at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Delegate.cs:284 

at System.LightupServices.CreateDelegate (System.Type type, System.Object instance, Sy

stem.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0 

at System.Lightup.CreateMethodAccessor (System.Type type, System.String name, Boolean bindInstance) [0x00000] in <filename unknown>:0 

at System.Lightup.GetMethodAccessor (System.Delegate& storage, System.Type type, System.String name, Boolean bindInstance) [0x00000] in <filename unknown>:0 

at System.Lightup.GetMethodAccessor[Func`1] (System.Delegate& storage, System.String name, Boolean bindInstance) [0x00000] in <filename unknown>:0 

at System.Lightup.Call[Int32] (System.Delegate& storage, System.String methodName) [0x00000] in <filename unknown>:0

at System.Lightup.Get[Int32] (System.Delegate& storage, System.String propertyName) [0x00000] in <filename unknown>:0 

at System.OperatingSystemLightup.get_Platform () [0x00000] in <filename unknown>:0 

at System.EnvironmentLightup.get_Platform () [0x00000] in <filename unknown>:0 

at System.EnvironmentLightup.TryGetProcessorCount (System.Int32& count) [0x00000] in <filename u

nknown>:0 

at System.EnvironmentLightup.get_ProcessorCount () [0x00000] in <filename unknown>:0 

at System.Threading.PlatformHelper.get_ProcessorCount () [0x00000] in <filename unknown>:0 

at System.Collections.Concurrent.ConcurrentDictionary`2[System.WeakReference,System.Object].get_DefaultConcurrencyLevel () [0x00000] in <filename unknown>:0 

at System.Collections.Concurrent.ConcurrentDictionary`2[System.WeakReference,System.Object]..ctor () [0x00000] in <filename unknown>:0 

at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)

at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:553 

--- End of inner exception stack trace ---

at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00016] in /Developer/MonoTouch/Source/mono/mc

s/class/corlib/System.Reflection/MonoMethod.cs:559 

at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x000af] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:329 

at System.Activator.CreateInstance (System.Type type) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Activator.cs:222 

at System.Threading.LazyInitializer+LazyHelpers`1[System.Collections.Concurrent.ConcurrentDictionary`2[System.WeakReference,System.Object]].ActivatorFactorySelector () [0x00000] in <filename unknown>:0 

at System.Threading.LazyInitializer.EnsureInitializedCore[ConcurrentDictionary`2] (System.Collections.Concurrent.ConcurrentDictionary`2& target, System.Func`1 valueFactory) [0x00000] in <filename unknown>:0 

at System.Threading.LazyInitializer.EnsureInitialized[ConcurrentDictionary`2] (System.Collections.Concurrent.ConcurrentDictionary`2& target) [0x00000] in <filename unknown>:0 

at System.Threading.Tasks.TaskScheduler.RegisterTaskScheduler (System.

Threading.Tasks.TaskScheduler ts) [0x00000] in <filename unknown>:0 

at System.Threading.Tasks.TaskScheduler..ctor () [0x00000] in <filename unknown>:0 

at System.Threading.Tasks.ThreadPoolTaskScheduler..ctor () [0x00000] in <filename unknown>:0 

at System.Threading.Tasks.TaskScheduler..cctor () [0x00000] in <filename unknown>:0 

--- End of inner exception stack trace ---

at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.PreventUnobservedTaskExceptions () [0x00000] in <filename unknown>:0 

at System.Runtime.CompilerServices.AsyncVoidMethodBuilder..cctor () [0x00000] in <filename unknown>:0 

--- End of inner exception stack trace ---

at AsyncTest.Core.Services.SimpleService.PingAsync (System.String text) [0x00000] in <filename unknown>:0 

at AsyncTest.Core.ViewModels.FirstViewModel+<Start>d__3.MoveNext () [0x0004f] in c:\Users\Ryan\Documents\Visual Studio 2012\Projects\AsyncTest\AsyncTest.Core\ViewModels\FirstViewModel.cs:32 


Unhandled Exception:

System.TypeInitializationException: A

The program 'Mono' has exited with code 0 (0x0).

The program '[15972] AsyncTestTouch.vshost.exe: Program Trace' has exited with code 0 (0x0).

The program '[15972] AsyncTestTouch.vshost.exe: Managed (v4.0.30319)' has exited with code -1 (0xffffffff).
Thanks in advance for any assistance you can provide!Ryan
Comment 1 Rolf Bjarne Kvinge [MSFT] 2013-08-05 08:44:32 UTC
It looks like this is somehow PCL related.

If I reference /Developer/MonoTouch/usr/lib/mono/2.1/Facades/System.Threading.Tasks.dll it works (by default this one is picked up: packages/Microsoft.Bcl.1.1.3/lib/portable-net40+sl4+win8+wp8/ from the project directory).

Note that I couldn't make the project build on Xamarin Studio/Mac without modifying the references (I added references to mscorlib, System, System.Core and /Developer/MonoTouch/usr/lib/mono/2.1/Facades/System.Threading.Tasks.dll before it would compile)

Martin, can you have a look at what's going on?
Comment 2 Martin Baulig 2016-11-11 09:35:24 UTC
Closing ancient bugs, please reopen if you're still having this problem.