Skip to content

Crash in GetHashCode with generic record #72181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dr1rrb opened this issue Jul 14, 2022 · 18 comments · Fixed by mono/mono#21531 or Unity-Technologies/mono#2127
Closed

Crash in GetHashCode with generic record #72181

dr1rrb opened this issue Jul 14, 2022 · 18 comments · Fixed by mono/mono#21531 or Unity-Technologies/mono#2127
Assignees
Milestone

Comments

@dr1rrb
Copy link

dr1rrb commented Jul 14, 2022

Description

In a library, I've a generic record that inherits from another generic record https://github.com/unoplatform/uno.extensions/blob/450d19f8fd9d4c53f327e5ecddbeeb50f86b020f/src/Uno.Extensions.Reactive/Operators/FeedToListFeedAdapter.cs#L14, but as soon as I try to use an instance of that record in a Dictionary my app is crashing.

Reproduction Steps

Unfortunately I was not able to create a repro for that issue. But here are the working (with an explicit GetHashCode) and failing version of my app on iOS.
working-Commerce.iOS.app.zip
crashing-Commerce.iOS.app.zip
.

Expected behavior

No crash :)

Actual behavior

Using mono for Android and iOS the app is crashing while using the same library is working fine on UWP / WinUI. Didn't test WebAssembly.

On Android I get a SIGABRT

[libc] Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 5768 (mmerce.Commerce), pid 5768 (mmerce.Commerce)

On iOS I get that stack trace:


=================================================================
	Managed Stacktrace:
=================================================================
	  at <unknown> <0xffffffff>
	  at Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`1:GetHashCode <0x0004a>
	  at Uno.Extensions.Reactive.ListStateImpl`1:GetHashCode <0x0004a>
	  at System.Collections.Generic.ObjectEqualityComparer`1:GetHashCode <0x000aa>
	  at Uno.Extensions.Reactive.Operators.ListFeedToFeedAdapter`1:GetHashCode <0x0012c>
	  at System.Collections.Generic.Dictionary`2:FindEntry <0x001e6>
	  at System.Collections.Generic.Dictionary`2:TryGetValue <0x0008a>
	  at Uno.Extensions.Reactive.Core.StateStore:GetOrCreateState <0x0045a>
	  at Uno.Extensions.Reactive.Core.SourceContext:GetOrCreateStateCore <0x00375>
	  at Uno.Extensions.Reactive.Core.SourceContext:GetOrCreateListState <0x000fa>
	  at Uno.Extensions.Reactive.Bindings.BindableListFeed`1:.ctor <0x00132>
	  at BindableDealsViewModel:.ctor <0x006b2>
	  at <Module>:runtime_invoke_void__this___object_object_object <0x001ff>
	  at <unknown> <0xffffffff>
	  at System.Reflection.RuntimeConstructorInfo:InternalInvoke <0x00100>
	  at System.Reflection.RuntimeConstructorInfo:InternalInvoke <0x0029a>
	  at System.Reflection.RuntimeConstructorInfo:DoInvoke <0x004ea>
	  at System.Reflection.RuntimeConstructorInfo:Invoke <0x0009a>
	  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver:VisitConstructor <0x0038d>
	  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2:VisitCallSiteMain <0x00398>
	  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver:VisitDisposeCache <0x000dd>
	  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2:VisitCallSite <0x00564>
	  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver:Resolve <0x00237>
	  at <>c__DisplayClass2_0:<RealizeService>b__0 <0x000d2>
	  at Microsoft.Extensions.DependencyInjection.ServiceProvider:GetService <0x001eb>
	  at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope:GetService <0x00122>
	  at <CreateViewModel>d__8:MoveNext <0x00c4d>
	  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:Start <0x00202>
	  at Uno.Extensions.Navigation.Navigators.ControlNavigator:CreateViewModel <0x0029a>
	  at <InitializeCurrentView>d__9:MoveNext <0x006da>
	  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:Start <0x0021a>
	  at Uno.Extensions.Navigation.Navigators.ControlNavigator`1:InitializeCurrentView <0x002bc>
	  at <NavigateForwardAsync>d__10:MoveNext <0x016a2>
	  at MoveNextRunner:InvokeMoveNext <0x000ab>
	  at System.Threading.ExecutionContext:RunInternal <0x00585>
	  at System.Threading.ExecutionContext:Run <0x00092>
	  at MoveNextRunner:Run <0x001aa>
	  at System.Threading.Tasks.AwaitTaskContinuation:InvokeAction <0x00093>
	  at System.Threading.Tasks.AwaitTaskContinuation:RunCallback <0x00153>
	  at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run <0x0013a>
	  at System.Threading.Tasks.Task:FinishContinuations <0x006ae>
	  at System.Threading.Tasks.Task:FinishStageThree <0x0015a>
	  at System.Threading.Tasks.Task`1:TrySetResult <0x0026a>
	  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult <0x002da>
	  at <Show>d__14:MoveNext <0x010ea>
	  at MoveNextRunner:InvokeMoveNext <0x000ab>
	  at System.Threading.ExecutionContext:RunInternal <0x00585>
	  at System.Threading.ExecutionContext:Run <0x00092>
	  at MoveNextRunner:Run <0x001aa>
	  at System.Threading.Tasks.AwaitTaskContinuation:InvokeAction <0x00093>
	  at System.Threading.Tasks.AwaitTaskContinuation:RunCallback <0x00153>
	  at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run <0x0013a>
	  at System.Threading.Tasks.Task:FinishContinuations <0x006ae>
	  at System.Threading.Tasks.Task:FinishStageThree <0x0015a>
	  at System.Threading.Tasks.Task`1:TrySetResult <0x00262>
	  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult <0x002e2>
	  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult <0x0014a>
	  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetResult <0x00082>
	  at <EnsurePageLoaded>d__15:MoveNext <0x006ba>
	  at MoveNextRunner:InvokeMoveNext <0x000ab>
	  at System.Threading.ExecutionContext:RunInternal <0x00585>
	  at System.Threading.ExecutionContext:Run <0x00092>
	  at MoveNextRunner:Run <0x001aa>
	  at System.Threading.Tasks.AwaitTaskContinuation:InvokeAction <0x00093>
	  at System.Threading.Tasks.AwaitTaskContinuation:RunCallback <0x00153>
	  at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run <0x0013a>
	  at System.Threading.Tasks.Task:FinishContinuations <0x006ae>
	  at System.Threading.Tasks.Task:FinishStageThree <0x0015a>
	  at System.Threading.Tasks.Task`1:TrySetResult <0x0022a>
	  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult <0x002b2>
	  at <EnsureLoaded>d__6:MoveNext <0x0088a>
	  at MoveNextRunner:InvokeMoveNext <0x000ab>
	  at System.Threading.ExecutionContext:RunInternal <0x00585>
	  at System.Threading.ExecutionContext:Run <0x00092>
	  at MoveNextRunner:Run <0x001aa>
	  at System.Threading.Tasks.AwaitTaskContinuation:InvokeAction <0x00093>
	  at System.Threading.Tasks.AwaitTaskContinuation:RunCallback <0x00153>
	  at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run <0x0013a>
	  at System.Threading.Tasks.Task:FinishContinuations <0x006ae>
	  at System.Threading.Tasks.Task:FinishStageThree <0x0015a>
	  at System.Threading.Tasks.Task`1:TrySetResult <0x0022a>
	  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:SetResult <0x002b2>
	  at System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder`1:SetResult <0x000a2>
	  at <ExecuteAsync>d__0`1:MoveNext <0x006f2>
	  at MoveNextRunner:InvokeMoveNext <0x000ab>
	  at System.Threading.ExecutionContext:RunInternal <0x00585>
	  at System.Threading.ExecutionContext:Run <0x00092>
	  at MoveNextRunner:Run <0x001aa>
	  at System.Threading.Tasks.AwaitTaskContinuation:InvokeAction <0x00093>
	  at System.Threading.Tasks.AwaitTaskContinuation:RunCallback <0x00153>
	  at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation:Run <0x0013a>
	  at System.Threading.Tasks.Task:FinishContinuations <0x006ae>
	  at System.Threading.Tasks.Task:FinishStageThree <0x0015a>
	  at System.Threading.Tasks.Task`1:TrySetResult <0x0022a>
	  at System.Threading.Tasks.TaskCompletionSource`1:TrySetResult <0x00092>
	  at System.Threading.Tasks.TaskCompletionSource`1:SetResult <0x0007a>
	  at <<ExecuteAsync>b__0>d:MoveNext <0x0046a>
	  at System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start <0x0020a>
	  at <>c__DisplayClass0_0`1:<ExecuteAsync>b__0 <0x0014a>
	  at <>c__DisplayClass6_0:<TryEnqueue>b__0 <0x0006f>
	  at Uno.UI.Dispatching.CoreDispatcher:InvokeOperation <0x00460>
	  at Uno.UI.Dispatching.CoreDispatcher:InvokeOperationSafe <0x0008a>
	  at Uno.UI.Dispatching.CoreDispatcher:DispatchItems <0x0070a>
	  at CoreFoundation.DispatchQueue:static_dispatcher_to_managed <0x0032f>
	  at CoreFoundation.DispatchQueue:static_dispatcher_to_managed <0x0010a>
	  at <unknown> <0xffffffff>
	  at UIKit.UIApplication:UIApplicationMain <0x00254>
	  at UIKit.UIApplication:Main <0x002da>
	  at Commerce.iOS.Application:Main <0x00092>
	  at <Module>:runtime_invoke_void_object <0x001a8>
=================================================================
The app has been terminated.
x

Regression?

No response

Known Workarounds

I've implemented my own GetHashCode https://github.com/unoplatform/uno.extensions/blob/450d19f8fd9d4c53f327e5ecddbeeb50f86b020f/src/Uno.Extensions.Reactive/Operators/FeedToListFeedAdapter.cs#L96

Configuration

Dev machine:

  • Win 11 21H2

  • VS 2022 17.3 pre 1.1
    Microsoft Visual Studio Enterprise 2022
    Version 17.3.0 Preview 1.1
    VisualStudio.17.Preview/17.3.0-pre.1.1+32519.111
    Microsoft .NET Framework
    Version 4.8.04161
    
    Installed Version: Enterprise
    
    Visual C++ 2022   00476-80000-00000-AA270
    Microsoft Visual C++ 2022
    
    .NET Core Debugging with WSL   1.0
    .NET Core Debugging with WSL
    
    ASP.NET and Web Tools 2019   17.3.122.33185
    ASP.NET and Web Tools 2019
    
    Azure App Service Tools v3.0.0   17.3.122.33185
    Azure App Service Tools v3.0.0
    
    Azure Functions and Web Jobs Tools   17.3.122.33185
    Azure Functions and Web Jobs Tools
    
    C# Tools   4.3.0-1.22254.1+9919d7e7bd753404a5d2328e5e3fb2de635169f3
    C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
    
    Common Azure Tools   1.10
    Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
    
    Extensibility Message Bus   1.2.6 (master@34d6af2)
    Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.
    
    Microsoft Azure Tools for Visual Studio   2.9
    Support for Azure Cloud Services projects
    
    Microsoft JVM Debugger   1.0
    Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
    
    Mono Debugging for Visual Studio   17.3.11 (4f73250)
    Support for debugging Mono processes with Visual Studio.
    
    Node.js Tools   1.5.40427.1 Commit Hash:d6dd02cc1b56ad1cb24b4ef0c48a81a985bbc64c
    Adds support for developing and debugging Node.js apps in Visual Studio
    
    NuGet Package Manager   6.3.0
    NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
    
    Razor (ASP.NET Core)   17.0.0.2222701+751db1ebea5e6a9ecc7fa57fe447180422afa610
    Provides languages services for ASP.NET Core Razor.
    
    SQL Server Data Tools   17.0.62204.01010
    Microsoft SQL Server Data Tools
    
    TypeScript Tools   17.0.10420.2001
    TypeScript Tools for Microsoft Visual Studio
    
    UnoPlatformPackage Extension   1.0
    UnoPlatformPackage Visual Studio Extension Detailed Info
    
    Visual Basic Tools   4.3.0-1.22254.1+9919d7e7bd753404a5d2328e5e3fb2de635169f3
    Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
    
    Visual F# Tools   17.1.0-beta.22178.3+6da0245a7ce4bb8483b8d1f2993c8ecaea967ad9
    Microsoft Visual F# Tools
    
    Visual Studio IntelliCode   2.2
    AI-assisted development for Visual Studio.
    
    VisualStudio.DeviceLog   1.0
    Information about my package
    
    VisualStudio.Mac   1.0
    Mac Extension for Visual Studio
    
    VSPackage Extension   1.0
    VSPackage Visual Studio Extension Detailed Info
    
    Xamarin   17.3.0.151 (d17-3-p1.1@5a59bfa)
    Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
    
    Xamarin Designer   17.3.0.33 (remotes/origin/d17-3-1@9c0d11a29)
    Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
    
    Xamarin Templates   17.2.15 (2e3b60e)
    Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.
    
    Xamarin.Android SDK   12.3.99.58 (main/64b22fc)
    Xamarin.Android Reference Assemblies and MSBuild support.
        Mono: adf1bc4
        Java.Interop: xamarin/java.interop/release/6.0.3xx@2a882d2d
        ProGuard: Guardsquare/proguard/v7.0.1@912d149
        SQLite: xamarin/sqlite/3.38.2@7b1e016
        Xamarin.Android Tools: xamarin/xamarin-android-tools/main@fc3c2ac
    
    
    Xamarin.iOS and Xamarin.Mac SDK   15.11.0.183 (f8314a435)
    Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
    

Mac:

  • VS for MAC 2019 v8.10.22 build 11
    === Visual Studio Enterprise 2019 for Mac ===
    
    Version 8.10.22 (build 11)
    Installation UUID: eac49913-0823-40de-a49d-50b6a14dc49f
    	GTK+ 2.24.23 (Raleigh theme)
    	Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)
    
    	Package version: 612000174
    
    === Mono Framework MDK ===
    
    Runtime:
    	Mono 6.12.0.174 (2020-02/adf1bc4335d) (64-bit)
    	Package version: 612000174
    
    === Roslyn (Language Service) ===
    
    3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb
    
    === NuGet ===
    
    Version: 5.9.0.7134
    
    === .NET SDK (x64) ===
    
    SDK: /usr/local/share/dotnet/sdk/5.0.407/Sdks
    SDK Versions:
    	5.0.407
    	5.0.404
    	5.0.403
    	5.0.400
    	5.0.302
    	5.0.103
    	5.0.100
    	3.1.418
    	3.1.416
    	3.1.415
    	3.1.412
    	3.1.411
    	3.1.406
    	3.1.302
    	3.1.200
    MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks
    
    === .NET Core Runtime ===
    
    Runtime: /usr/local/share/dotnet/dotnet
    Runtime Versions:
    	5.0.16
    	5.0.13
    	5.0.12
    	5.0.9
    	5.0.8
    	5.0.3
    	5.0.0
    	3.1.24
    	3.1.22
    	3.1.21
    	3.1.18
    	3.1.17
    	3.1.12
    	3.1.6
    	3.1.2
    	2.1.23
    	2.1.20
    	2.1.17
    	2.1.16
    
    === .NET Core 3.1 SDK ===
    
    SDK: 3.1.418
    
    === .NET 5.0 SDK ===
    
    SDK: 5.0.407
    
    === Xamarin.Profiler ===
    
    Version: 1.6.13.11
    Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
    
    === Updater ===
    
    Version: 11
    
    === Xamarin.Android ===
    
    Version: 12.2.4.3 (Visual Studio Enterprise)
    Commit: xamarin-android/d17-1/fc1125e
    Android SDK: /Users/david/Library/Developer/Xamarin/android-sdk-macosx
    	Supported Android versions:
    		8.0 (API level 26)
    
    SDK Tools Version: 26.1.1
    SDK Platform Tools Version: 29.0.5
    SDK Build Tools Version: 29.0.2
    
    Build Information: 
    Mono: adf1bc4
    Java.Interop: xamarin/java.interop/d17-1@7ac33610
    ProGuard: Guardsquare/proguard/v7.0.1@912d149
    SQLite: xamarin/sqlite/3.37.1@0893b3b
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-1@db125a7
    
    === Eclipse Temurin JDK ===
    
    Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home
    1.8.0.302
    Android Designer EPL code available here:
    https://github.com/xamarin/AndroidDesigner.EPL
    
    === Android SDK Manager ===
    
    Version: 16.10.0.13
    Hash: 1b81df5
    Branch: remotes/origin/d16-10
    Build date: 2021-11-12 00:17:32 UTC
    
    === Android Device Manager ===
    
    Version: 16.10.0.15
    Hash: 89dcc0b
    Branch: remotes/origin/d16-10
    Build date: 2021-11-12 00:17:52 UTC
    
    === Apple Developer Tools ===
    
    Xcode 13.3 (20102)
    Build 13E113
    
    === Xamarin.Mac ===
    
    Version: 8.8.0.3 (Visual Studio Enterprise)
    Hash: eb7f8ed35
    Branch: xcode13.3
    Build date: 2022-03-30 03:16:09-0400
    
    === Xamarin.iOS ===
    
    Version: 15.9.0.100 (Visual Studio Enterprise)
    Hash: cf971a68e
    Branch: main
    Build date: 2022-03-31 03:15:41-0400
    
    === Xamarin Designer ===
    
    Version: 16.11.0.60
    Hash: 56f9b80b0
    Branch: remotes/origin/d16-11
    Build date: 2021-12-15 01:44:16 UTC
    
    === Build Information ===
    
    Release ID: 810220011
    Git revision: 16b49eb779f7def4523bbc8f4407628cf8dbb4b5
    Build date: 2022-04-07 05:04:03-04
    Build branch: release-8.10
    
    === Operating System ===
    
    Mac OS X 12.3.0
    Darwin 21.4.0 Darwin Kernel Version 21.4.0
    	Mon Feb 21 20:34:37 PST 2022
    	root:xnu-8020.101.4~2/RELEASE_X86_64 x86_64
    
    
    
  • Simulator: iPad pro 5th gen iOS 15.4

Other information

No response

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 14, 2022
@spouliot
Copy link
Contributor

@vargaz does that ring any bells to you It seems mono does not like the compiler generated GetHashCode ?!? thanks!

@vargaz
Copy link
Contributor

vargaz commented Jul 15, 2022

Would need some kind of testcase to track this down.

@marek-safar
Copy link
Contributor

C# records generate complex generic calls. @dr1rrb could you attach the compiled assembly or share what's record generated GetHashCode IL ?

@dr1rrb
Copy link
Author

dr1rrb commented Jul 19, 2022

C# records generate complex generic calls. @dr1rrb could you attach the compiled assembly or share what's record generated GetHashCode IL ?

@marek-safar The source code is here https://github.com/unoplatform/uno.extensions/blob/450d19f8fd9d4c53f327e5ecddbeeb50f86b020f/src/Uno.Extensions.Reactive/Operators/FeedToListFeedAdapter.cs#L14 The issue occurs when I use one instance of this in a dictionary (and I remove the GetHashCode I've added to workaround the issue).

For the IL, it's a netstandard 2.0 library that is working on other platforms, that's why I sent your the whole app (with the magic of the linker ^^ - working and crashing), but here is what I get from ILSpy:

For the FeedToListFeedAdapter``1

.method public hidebysig virtual 
	instance int32 GetHashCode () cil managed 
{
	.custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
		01 00 00 00
	)
	// Method begins at RVA 0x7409
	// Header size: 1
	// Code size: 7 (0x7)
	.maxstack 8

	IL_0000: ldarg.0
	IL_0001: call instance int32 class Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`2<class [System.Collections.Immutable]System.Collections.Immutable.IImmutableList`1<!T>, !T>::GetHashCode()
	IL_0006: ret
} // end of method FeedToListFeedAdapter`1::GetHashCode

For the FeedToListFeedAdapter``2

.method public hidebysig virtual 
	instance int32 GetHashCode () cil managed 
{
	.custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
		01 00 00 00
	)
	// Method begins at RVA 0x76f0
	// Header size: 12
	// Code size: 109 (0x6d)
	.maxstack 3

	IL_0000: call class [netstandard]System.Collections.Generic.EqualityComparer`1<!0> class [netstandard]System.Collections.Generic.EqualityComparer`1<class [netstandard]System.Type>::get_Default()
	IL_0005: ldarg.0
	IL_0006: callvirt instance class [netstandard]System.Type class Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`2<!TCollection, !TItem>::get_EqualityContract()
	IL_000b: callvirt instance int32 class [netstandard]System.Collections.Generic.EqualityComparer`1<class [netstandard]System.Type>::GetHashCode(!0)
	IL_0010: ldc.i4 -1521134295
	IL_0015: mul
	IL_0016: call class [netstandard]System.Collections.Generic.EqualityComparer`1<!0> class [netstandard]System.Collections.Generic.EqualityComparer`1<class Uno.Extensions.Reactive.IFeed`1<!TCollection>>::get_Default()
	IL_001b: ldarg.0
	IL_001c: ldfld class Uno.Extensions.Reactive.IFeed`1<!0> class Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`2<!TCollection, !TItem>::'<Source>k__BackingField'
	IL_0021: callvirt instance int32 class [netstandard]System.Collections.Generic.EqualityComparer`1<class Uno.Extensions.Reactive.IFeed`1<!TCollection>>::GetHashCode(!0)
	IL_0026: add
	IL_0027: ldc.i4 -1521134295
	IL_002c: mul
	IL_002d: call class [netstandard]System.Collections.Generic.EqualityComparer`1<!0> class [netstandard]System.Collections.Generic.EqualityComparer`1<class [netstandard]System.Func`2<!TCollection, class [System.Collections.Immutable]System.Collections.Immutable.IImmutableList`1<!TItem>>>::get_Default()
	IL_0032: ldarg.0
	IL_0033: ldfld class [netstandard]System.Func`2<!0, class [System.Collections.Immutable]System.Collections.Immutable.IImmutableList`1<!1>> class Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`2<!TCollection, !TItem>::'<ToImmutable>k__BackingField'
	IL_0038: callvirt instance int32 class [netstandard]System.Collections.Generic.EqualityComparer`1<class [netstandard]System.Func`2<!TCollection, class [System.Collections.Immutable]System.Collections.Immutable.IImmutableList`1<!TItem>>>::GetHashCode(!0)
	IL_003d: add
	IL_003e: ldc.i4 -1521134295
	IL_0043: mul
	IL_0044: call class [netstandard]System.Collections.Generic.EqualityComparer`1<!0> class [netstandard]System.Collections.Generic.EqualityComparer`1<valuetype Uno.Extensions.Reactive.Collections.ItemComparer`1<!TItem>>::get_Default()
	IL_0049: ldarg.0
	IL_004a: ldfld valuetype Uno.Extensions.Reactive.Collections.ItemComparer`1<!1> class Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`2<!TCollection, !TItem>::'<ItemComparer>k__BackingField'
	IL_004f: callvirt instance int32 class [netstandard]System.Collections.Generic.EqualityComparer`1<valuetype Uno.Extensions.Reactive.Collections.ItemComparer`1<!TItem>>::GetHashCode(!0)
	IL_0054: add
	IL_0055: ldc.i4 -1521134295
	IL_005a: mul
	IL_005b: call class [netstandard]System.Collections.Generic.EqualityComparer`1<!0> class [netstandard]System.Collections.Generic.EqualityComparer`1<class Uno.Extensions.Collections.Tracking.CollectionAnalyzer`1<!TItem>>::get_Default()
	IL_0060: ldarg.0
	IL_0061: ldfld class Uno.Extensions.Collections.Tracking.CollectionAnalyzer`1<!1> class Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`2<!TCollection, !TItem>::_analyzer
	IL_0066: callvirt instance int32 class [netstandard]System.Collections.Generic.EqualityComparer`1<class Uno.Extensions.Collections.Tracking.CollectionAnalyzer`1<!TItem>>::GetHashCode(!0)
	IL_006b: add
	IL_006c: ret
} // end of method FeedToListFeedAdapter`2::GetHashCode

You can find the assembly itself on nuget: https://www.nuget.org/packages/Uno.Extensions.Reactive/2.2.0-dev.8 (version dev.8 is the latest version with the bug, versions after include my workaround)

@ivanpovazan
Copy link
Member

Hello @dr1rrb, I am trying to extract your use case into a reproducible (crashing) sample as @vargaz suggested.

Would it be possible for you to provide the instantiation of BindableListFeed which was causing the crash?
Additionally, does this happen both in Debug and Release configurations?

@dr1rrb
Copy link
Author

dr1rrb commented Jul 26, 2022

Yes the crash happen in both debug and release.

BTW, if it helps you, the source code of the app is here https://github.com/unoplatform/Uno.Samples/tree/master/reference/Uno.Extensions.Commerce (it's a sample app, you can pass the login page just by entering dummy content)

In the app source code, the crash is caused by this line: https://github.com/unoplatform/Uno.Samples/blob/d29881785845b484480fc0c125a210c1cc1d5c0b/reference/Uno.Extensions.Commerce/Commerce/ViewModels/DealsViewModel.cs#L23 in the DealsViewModel for which we generate a nested class BindableDealsViewModel which will instantiate the BindableListFeed directly in its constructor :

Favorites = new global::Uno.Extensions.Reactive.Bindings.BindableListFeed<Commerce.Business.Models.Product>(
	nameof(Favorites),
	vm.Favorites ?? throw new NullReferenceException("The list feed property 'Favorites' is null. Public feeds properties must be initialized in the constructor."),
	ctx);

FYI In the sample project, the generated source code can be found here:
image

@ivanpovazan
Copy link
Member

Commerce app crash repro

I have managed to reproduce the reported issue when using Xamarin iOS with legacy mono:

  1. Checkout the sample app
  2. Change version of referenced Uno.Extensions.* to 2.2.0-dev.8 in the *.props files
  3. Build and run the Commerce.iOS in VS for Mac 2022
  4. Perform some actions in the app: log in, add some items, etc

I get the following error on the simulator:

2022-07-28 19:46:08.933000+0200 Commerce.iOS[18142:400335] error: * Assertion at /Users/builder/jenkins/workspace/archive-mono/2020-02/ios/release/mono/mini/method-to-ir.c:7241, condition `is_ok (error)' not met, function:mono_method_to_ir, VAR 1 (TItem_REF) cannot be expanded in this context with 1 instantiations

With the same Managed stack trace:

=================================================================
	Managed Stacktrace:
=================================================================
	  at <unknown> <0xffffffff>
	  at Uno.Extensions.Reactive.Operators.FeedToListFeedAdapter`1:GetHashCode <0x0004a>
	  at System.Collections.Generic.ObjectEqualityComparer`1:GetHashCode <0x000aa>
	  at Uno.Extensions.Reactive.Operators.ListFeedToFeedAdapter`1:GetHashCode <0x0012c>
	  at System.Collections.Generic.Dictionary`2:FindEntry <0x001e6>
	  at System.Collections.Generic.Dictionary`2:TryGetValue <0x0008a>
	  at Uno.Extensions.Reactive.Core.StateStore:GetOrCreateState <0x00392>
	  at Uno.Extensions.Reactive.Core.SourceContext:GetOrCreateStateCore <0x00375>
	  at Uno.Extensions.Reactive.Core.SourceContext:GetOrCreateListState <0x000fa>
	  at Uno.Extensions.Reactive.Bindings.BindableListFeed`1:.ctor <0x00132>
	  at BindableProductDetailsViewModel:.ctor <0x00752>

The error message

From the error message we can see that the issue occurs in the JIT compiler.
To confirm the failure, we can also choose to target a device (if there is no actual testing device connected to the host we can choose iOS Build Only Device:Generic Device configuration in VS) instead of the simulator, which will make the compiler build the app in fullAOT mode.
The AOT compilation should fail and the same error will be reported in the build phase.

@dr1rrb Could you please try this out and confirm?


Already fixed?

If this is the case, then this issue seems to be the same as #57560, which was fixed for .NET6 but was not backported to mono repo.
I have tried the similar-smaller repro sample (see below) on .NET7 and could not reproduce the failure I am getting on legacy mono.
@vargaz @marek-safar should this issue be moved to the https://github.com/mono/mono ?

The smaller repro (on legacy mono)

  1. Create a brand new iOS app from the Single View App template in VisualStudio
  2. Replace the code from Main.cs with
using UIKit;
using System.Collections.Generic;
using System.Collections.Immutable;
using Uno.Extensions.Reactive;

namespace HelloWorld
{
    public class Application
    {
        // This is the main entry point of the application.
        static void Main(string[] args)
        {
            var dict = new Dictionary<object, int>();
            var listFeed = Feed
                .Async(async ct => new[] { new object() })
                .Select(list => list.ToImmutableList())
                .AsListFeed();
            var listFeedAsFeed = listFeed.AsFeed();
            var listFeedAsFeedAsListFeed = listFeedAsFeed.AsListFeed();
            var listFeedAsFeedAsListFeedAsFeed = listFeedAsFeedAsListFeed.AsFeed();

            var inserted = dict.TryGetValue(listFeedAsFeedAsListFeedAsFeed, out var existing)
                ? existing
                : (dict[listFeedAsFeedAsListFeedAsFeed] = 42);

            UIApplication.Main(args, null, typeof(AppDelegate));
        }
	}
}
  1. Add appropriate package references in the project file:
  <ItemGroup>
    <PackageReference Include="Uno.Extensions.Reactive" Version="2.2.0-dev.8" />
    <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0.0" />
  </ItemGroup>

@dr1rrb
Copy link
Author

dr1rrb commented Aug 1, 2022

@dr1rrb Could you please try this out and confirm?

I do! When I try to build the "Commerce" sample app targeting a device (in release), the OAT fails:

1>  C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(235,3): error MT3001: Could not AOT the assembly '/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/3-Build/Uno.Extensions.Reactive.dll'

@spouliot
Copy link
Contributor

spouliot commented Aug 2, 2022

@dr1rrb MT3001 is a catch-all error code of Xamarin.iOS when running the AOT compiler. Basically it means "we called the AOT compiler" but we can't find any output.

The most common case is that the AOT compiler crashed. Your build logs should have some trace of that crash. The Mac's Console.app should also have a crash report for the compiler.

@ivanpovazan
Copy link
Member

The most common case is that the AOT compiler crashed. Your build logs should have some trace of that crash. The Mac's Console.app should also have a crash report for the compiler.

The build log in VisualStudio should have a line stating the cause of the failure. From what I described above that line should be something like:

2022-07-28 19:46:08.933000+0200 Commerce.iOS[18142:400335] error: * Assertion at /Users/builder/jenkins/workspace/archive-mono/2020-02/ios/release/mono/mini/method-to-ir.c:7241, condition `is_ok (error)' not met, function:mono_method_to_ir, VAR 1 (TItem_REF) cannot be expanded in this context with 1 instantiations

@dr1rrb it would be great if you could confirm this.

@dr1rrb
Copy link
Author

dr1rrb commented Aug 2, 2022

@spouliot @ivanpovazan

Indeed, I didn't scroll the log enough:

1>  MTouch: 2022-08-02T10:45:57.3782861-04:00 - Logging messages
1>  /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch @/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/response-file.rsp "--setenv=MONO_GC_PARAMS=soft-heap-limit=512m,nursery-size=64m,evacuation-threshold=66,major=marksweep,concurrent-sweep" 
1>  Xamarin.iOS 15.10.0.5 (d17-2: 96b3edb6d) using framework: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk
1>  AOT Compilation exited with code 134, command:
1>  MONO_PATH=/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/3-Build /Library/Frameworks/Xamarin.iOS.framework/Versions/15.10.0.5/bin/arm64-darwin-mono-sgen --debug --llvm -O=gsharedvt -O=-float32 --aot=mtriple=arm64-ios,data-outfile=/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/arm64/Uno.Extensions.Reactive.aotdata.arm64,static,asmonly,direct-icalls,full,readonly-value=ObjCRuntime.Runtime.Arch=i4/0,nodebug,dwarfdebug,msym-dir=/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/3-Build/Msym,llvm-path=/Library/Frameworks/Xamarin.iOS.framework/Versions/15.10.0.5/LLVM/bin/,outfile=/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/arm64/Uno.Extensions.Reactive.dll.s,llvm-outfile=/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/arm64/Uno.Extensions.Reactive.dll-llvm.o /Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/3-Build/Uno.Extensions.Reactive.dll
1>  Mono Ahead of Time compiler - compiling assembly /Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/3-Build/Uno.Extensions.Reactive.dll
1>  AOTID 2604B0B2-C0F0-4563-CDC2-B9E379462159
1>  * Assertion at /Users/builder/jenkins/workspace/archive-mono/2020-02/ios/release/mono/mini/method-to-ir.c:7241, condition `is_ok (error)' not met, function:mono_method_to_ir, VAR 1 (TItem_REF) cannot be expanded in this context with 1 instantiations
1>  
1>C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(235,3): error MT3001: Could not AOT the assembly '/Users/david/Library/Caches/Xamarin/mtbs/builds/Commerce.iOS/fa47e299a41d206017070f669485f2d73de2e05cd5e6e63edb345ccc4da85e2f/obj/iPhone/Release/mtouch-cache/3-Build/Uno.Extensions.Reactive.dll'

So yes it's the same assertion that fails

@dr1rrb
Copy link
Author

dr1rrb commented Aug 2, 2022

Hey @ivanpovazan I just tried to build the "Commerce Sample App" with the version "2.2.0-dev.70" (which contains my workaround for the GetHashCode) and I noticed that the build (release - device) also fails on the AOT step. But if I target an emulator (still in release, but without AOT), the build succeed ... and my original bug (crash at runtime) is fixed.

I'm wondering if it's not 2 different issues.

Any thoughts?

(Going to try with our "simple repro")

@ivanpovazan
Copy link
Member

hey @dr1rrb, if it is failing with the same error message (mentioned above) in the fullAOT build - device build, then it is most likely the same issue.
Regarding the simulator, it is a bit more difficult to trigger the actual call which causes the problem, so the AOT build should be your measuring (repro) point.

@ivanpovazan ivanpovazan self-assigned this Aug 3, 2022
@SamMonoRT SamMonoRT removed the untriaged New issue has not been triaged by the area owner label Aug 3, 2022
@SamMonoRT
Copy link
Member

@ivanpovazan - other than backporting to mono\mono, does any more work remain for this for the dotnet/runtime repo for 7.0.0 ?

@ivanpovazan
Copy link
Member

@SamMonoRT, I don't think so

@SamMonoRT
Copy link
Member

No work remains for 7.0.0 @ivanpovazan will validate the fix on the mono\mono repo and close this issue.

@dr1rrb
Copy link
Author

dr1rrb commented Aug 3, 2022

hey @dr1rrb, if it is failing with the same error message (mentioned above) in the fullAOT build - device build, then it is most likely the same issue. Regarding the simulator, it is a bit more difficult to trigger the actual call which causes the problem, so the AOT build should be your measuring (repro) point.

FYI, to workaround the build issue we do have on projects (including our sample "commerce app") I had to push my workaround further by converting my objects to class instead of record (and implement the GetHashCode and the Equals manually). So even if for me (which is not used to deal with that kind of issues) it's not "natural" that a runtime bug can be reproduced at build time with AOT, everything tends to show that you are right ... which is a good news 👍

Thanks for your support

akoeplinger pushed a commit to mono/mono that referenced this issue Aug 4, 2022
akoeplinger pushed a commit to mono/mono that referenced this issue Aug 4, 2022
Fixes dotnet/runtime#72181

Co-authored-by: Ivan Povazan <ivan.povazan@gmail.com>
@ghost ghost locked as resolved and limited conversation to collaborators Sep 3, 2022
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Nov 24, 2023
Changelog:
mono-6.12.0.199

Bump nuget.exe to v6.6.1

mono-6.12.0.198

Fix xar url again

(cherry picked from commit 3005442)

mono-6.12.0.190

Change download URL for PCL reference assemblies

mono-6.12.0.188

Bump NuGetSdkResolver in msbuild

mono-6.12.0.185

Backport fixes for sharing wrappers when type attributes are involved (…

…#21537)

* [wasm] Fix the handling of i8/u8 in get_wrapper_shared_type_full (). (#19859)

Previously, these were returned verbatim, which caused sharing issues when the type had
attributes.

Fixes #19841.

* [aot] Fix the handling of r4/r8 parameter types with attributes during generic sharing. (#20217)

The attributes need to be ignored as with the other types, otherwise gsharedvt wrappers for signatures with
parameters like double f = default will not be found.

Fixes #20195.

mono-6.12.0.184

Backporting dotnet/runtime#59861 (#21532)

Fixes dotnet/runtime#72181

mono-6.12.0.183

Backport dotnet/runtime#71436 (#21519)

Backport dotnet/runtime#71436
Backport of #21516 to 2020-02
ThomasKuehne pushed a commit to ThomasKuehne/mono that referenced this issue Mar 23, 2024
scott-ferguson-unity pushed a commit to Unity-Technologies/mono that referenced this issue Apr 23, 2025
scott-ferguson-unity pushed a commit to Unity-Technologies/mono that referenced this issue Apr 28, 2025
scott-ferguson-unity pushed a commit to Unity-Technologies/mono that referenced this issue Apr 28, 2025
scott-ferguson-unity pushed a commit to Unity-Technologies/mono that referenced this issue Apr 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.