Bug 36370

Summary: AOT: Can't insert into Dictionary<UInt32Enum, object>
Product: iOS Reporter: Rolf Bjarne Kvinge [MSFT] <rolf>
Component: Mono runtime / AOT compilerAssignee: Zoltan Varga <vargaz>
Status: RESOLVED FIXED    
Severity: normal CC: kumpera, mono-bugs+monotouch
Priority: ---    
Version: master   
Target Milestone: Untriaged   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Bug Depends on:    
Bug Blocks: 36259    
Attachments: test project

Description Rolf Bjarne Kvinge [MSFT] 2015-11-30 12:22:10 UTC
Repro:
  * Run attached program on device (the problem occurs on both armv7 or arm64)
  * Screen turns green on success, red on failure.

Failure:

> 2015-11-30 13:21:14.014 unifiedtestapp[259:12761] System.InvalidCastException: Specified cast is not valid.
>   at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_object_castclass_unbox (object,intptr)
>   at System.Array.UnsafeMov[S,R] (System.S instance) [0x00000] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/Array.cs:3206 
>   at (wrapper unknown) System.Object:gsharedvt_in ()
>   at (wrapper unknown) System.Object:gsharedvt_out ()
>   at System.Runtime.CompilerServices.JitHelpers.UnsafeEnumCast[T] (T val) [0x00000] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/ReferenceSources/JitHelpers.cs:14 
>   at (wrapper unknown) System.Object:gsharedvt_in ()
>   at (wrapper unknown) System.Object:gsharedvt_out ()
>   at System.Collections.Generic.EnumEqualityComparer`1[T].GetHashCode (T obj) [0x00000] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/equalitycomparer.cs:434 
>   at (wrapper unknown) System.Object:gsharedvt_in ()
>   at System.Collections.Generic.Dictionary`2[TKey,TValue].Insert (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value, Boolean add) [0x00023] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:326 
>   at System.Collections.Generic.Dictionary`2[TKey,TValue].set_Item (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value) [0x00000] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:187 
>   at AppDelegate.TickOnce () [0x0000f] in /Users/rolf/Projects/unified-test-app/AppDelegate.cs:64
Comment 1 Rolf Bjarne Kvinge [MSFT] 2015-11-30 12:43:07 UTC
Created attachment 14030 [details]
test project
Comment 2 Zoltan Varga 2015-12-01 17:54:53 UTC
Fixed in mono master a7a0f54d3af48c076939d9a99867c9dd6eb0e626, maccore master bumped in 7a8aa6cdc42bfca3e94fa45260eb475eae06009e.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2015-12-01 19:26:24 UTC
@Zoltan, it's fixed for uint32, but not for int8 and int16.

Code (replace AppDelegate.cs with this in the test project): https://gist.github.com/rolfbjarne/a439c2853a9b8f7907df

results in

> 2015-12-01 20:23:40.725 unifiedtestapp[4434:3668521] Success: UInt8Enum
> 2015-12-01 20:23:40.729 unifiedtestapp[4434:3668521] Success: UInt16Enum
> 2015-12-01 20:23:40.732 unifiedtestapp[4434:3668521] Success: UInt32Enum
> 2015-12-01 20:23:40.733 unifiedtestapp[4434:3668521] Success: UInt64Enum
> 2015-12-01 20:23:40.740 unifiedtestapp[4434:3668521] Failed: Int8Enum: System.InvalidCastException: Specified cast is not valid.
>   at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_object_castclass_unbox (object,intptr)
>   at System.Array.UnsafeMov[S,R] (System.S instance) [0x00000] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/Array.cs:3206 
>   at (wrapper unknown) System.Object:gsharedvt_in ()
>   at (wrapper unknown) System.Object:gsharedvt_out ()
>   at System.Runtime.CompilerServices.JitHelpers.UnsafeEnumCast[T] (T val) [0x00000] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/ReferenceSources/JitHelpers.cs:14 
>   at (wrapper unknown) System.Object:gsharedvt_in ()
>   at (wrapper unknown) System.Object:gsharedvt_out ()
>   at System.Collections.Generic.SByteEnumEqualityComparer`1[T].GetHashCode (T obj) [0x00000] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/equalitycomparer.cs:472 
>   at (wrapper unknown) System.Object:gsharedvt_in ()
>   at System.Collections.Generic.Dictionary`2[TKey,TValue].Insert (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value, Boolean add) [0x00023] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:326 
>   at System.Collections.Generic.Dictionary`2[TKey,TValue].set_Item (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value) [0x00000] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:187 
>   at AppDelegate.Test[T] () [0x00029] in /Users/rolf/Projects/unified-test-app/AppDelegate.cs:100 
> 2015-12-01 20:23:40.746 unifiedtestapp[4434:3668521] Failed: Int16Enum: System.InvalidCastException: Specified cast is not valid.
>   at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_object_castclass_unbox (object,intptr)
>   at System.Array.UnsafeMov[S,R] (System.S instance) [0x00000] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/Array.cs:3206 
>   at (wrapper unknown) System.Object:gsharedvt_in ()
>   at (wrapper unknown) System.Object:gsharedvt_out ()
>   at System.Runtime.CompilerServices.JitHelpers.UnsafeEnumCast[T] (T val) [0x00000] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/ReferenceSources/JitHelpers.cs:14 
>   at (wrapper unknown) System.Object:gsharedvt_in ()
>   at (wrapper unknown) System.Object:gsharedvt_out ()
>   at System.Collections.Generic.ShortEnumEqualityComparer`1[T].GetHashCode (T obj) [0x00000] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/equalitycomparer.cs:487 
>   at (wrapper unknown) System.Object:gsharedvt_in ()
>   at System.Collections.Generic.Dictionary`2[TKey,TValue].Insert (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value, Boolean add) [0x00023] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:326 
>   at System.Collections.Generic.Dictionary`2[TKey,TValue].set_Item (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value) [0x00000] in /work/maccore/master/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:187 
>   at AppDelegate.Test[T] () [0x00029] in /Users/rolf/Projects/unified-test-app/AppDelegate.cs:100 
> 2015-12-01 20:23:40.751 unifiedtestapp[4434:3668521] Success: Int32Enum
> 2015-12-01 20:23:40.754 unifiedtestapp[4434:3668521] Success: Int64Enum>
Comment 4 Zoltan Varga 2015-12-01 21:10:09 UTC
Fixed by the mono bump in 51cb78b8a087d1a98a4913460a7e45293f04cf42.