Repository navigation
Closed
Description
From @jhimes144 on Sun, 08 Jan 2023 04:51:56 GMT
This is an issue I have raised over in Avalonia here AvaloniaUI/Avalonia#9934
To the best of our knowledge, the below method GetStringNative should not have any problem with AOT, and everything works fine on Android with AOT enabled. So far I've reproduced this on two separate code bases.
Steps to Reproduce
- Create a new dotnet solution using the Avalonia xplat template. See https://github.com/AvaloniaUI/avalonia-dotnet-templates
- Insert needed
CodesignKeyin project file for the ios project - Build and run the ios project on a physical ios device
Expected Behavior
The app runs
Actual Behavior
The following exception is raised on app startup
System.ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-native) intptr Avalonia.OpenGL.GlBasicInfoInterface:wrapper_native_indirect_0x283931e40 (intptr&,int)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
at Avalonia.OpenGL.GlBasicInfoInterface.GetStringNative(Int32 v) in /_/src/Avalonia.OpenGL/DevGenerators/Generator.GetProcAddressInitializationGenerator/globalAvalonia.OpenGL.GlBasicInfoInterface.cs:13
at Avalonia.OpenGL.GlBasicInfoInterface.GetString(Int32 v) in /_/src/Avalonia.OpenGL/GlBasicInfoInterface.cs:27
at Avalonia.OpenGL.GlBasicInfoInterface.GetExtensions() in /_/src/Avalonia.OpenGL/GlBasicInfoInterface.cs:43
at Avalonia.OpenGL.GlInterface.GlContextInfo.Create(GlVersion version, Func`2 getProcAddress) in /_/src/Avalonia.OpenGL/GlInterface.cs:33
at Avalonia.OpenGL.GlInterface..ctor(GlVersion version, Func`2 getProcAddress) in /_/src/Avalonia.OpenGL/GlInterface.cs:48
at Avalonia.iOS.GlContext..ctor() in /_/src/iOS/Avalonia.iOS/EaglDisplay.cs:30
at Avalonia.iOS.EaglFeature..ctor() in /_/src/iOS/Avalonia.iOS/EaglDisplay.cs:17
at Avalonia.iOS.Platform.Register() in /_/src/iOS/Avalonia.iOS/Platform.cs:34
at at Avalonia.Controls.AppBuilderBase`1[[Avalonia.AppBuilder, Avalonia.Controls, Version=11.0.0.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b]].Setup()
at at Avalonia.Controls.AppBuilderBase`1[[Avalonia.AppBuilder, Avalonia.Controls, Version=11.0.0.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b]].SetupWithLifetime(IApplicationLifetime lifetime)
at at Avalonia.iOS.AvaloniaAppDelegate`1[[testapp.App, testapp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].FinishedLaunching(UIApplication application, NSDictionary launchOptions)
I have tried adding <ResolveAssemblyConflicts>true</ResolveAssemblyConflicts>, different linker settings, and downgrading the project to .net 6. All attempts failed with same error.
Environment
Visual Studio Community 2022 for Mac
Version 17.4.2 (build 17)
Installation UUID: 04eb36b5-8ade-4881-9f2c-f51e231033e1
Runtime
.NET 6.0.12 (64-bit)
Architecture: X64
Roslyn (Language Service)
4.4.0-6.22578.12+3c6ab8e1715e5b080fb7bb77070810ab71e09387
NuGet
Version: 6.3.1.1
.NET SDK (x64)
SDK: /usr/local/share/dotnet/sdk/7.0.101/Sdks
SDK Versions:
7.0.101
6.0.404
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks
.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
7.0.1
6.0.12
Xamarin.Profiler
Version: 1.8.0.19
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
Updater
Version: 11
Xamarin.Android
Version: 13.1.0.1 (Visual Studio Community)
Commit: xamarin-android/d17-4/13ba222
Android SDK: /Users/jhimes/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
13.0 (API level 33)
SDK Command-line Tools Version: 7.0
SDK Platform Tools Version: 33.0.2
SDK Build Tools Version: 32.0.0
Build Information:
Mono: a96bde9
Java.Interop: xamarin/java.interop/d17-4@fcc33ce2
SQLite: xamarin/sqlite/3.39.3@23e1ae7
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@0be567a
Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.12
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
Android SDK Manager
Version: 17.4.0.54
Hash: 6eabb9e
Branch: remotes/origin/d17-4
Build date: 2022-12-13 04:22:32 UTC
Android Device Manager
Version: 0.0.0.1206
Hash: 886af39
Branch: 886af39
Build date: 2022-12-13 04:22:32 UTC
Apple Developer Tools
Xcode 14.2 (21534)
Build 14C18
Xamarin.Mac
Version: 9.0.0.27 (Visual Studio Community)
Hash: 933c6c2c9
Branch: xcode14.1
Build date: 2022-11-22 02:00:36-0500
Xamarin.iOS
Version: 16.1.1.27 (Visual Studio Community)
Hash: 933c6c2c9
Branch: xcode14.1
Build date: 2022-11-22 02:00:37-0500
Xamarin Designer
Version: 17.4.0.136
Hash: d49c9ff6d3
Branch: remotes/origin/d17-4
Build date: 2022-12-13 04:22:27 UTC
Build Information
Release ID: 1704020017
Git revision: 7ef5413f2eec3351ce648085f619fc29fd8cb647
Build date: 2022-12-13 04:20:10+00
Build branch: release-17.4
Build lane: release-17.4
Operating System
Mac OS X 12.6.1
Darwin 21.6.0 Darwin Kernel Version 21.6.0
Thu Sep 29 20:12:57 PDT 2022
root:xnu-8020.240.7~1/RELEASE_X86_64 x86_64
Copied from original issue dotnet/macios#17159
Activity
rolfbjarne commentedon Jan 19, 2023
From @rolfbjarne on Thu, 19 Jan 2023 15:12:23 GMT
I can reproduce this with the provided sample and running on an iOS device.
Using ILSpy on this method
at Avalonia.OpenGL.GlBasicInfoInterface.GetStringNative(Int32 v)shows:and nothing in particular stands out to me, so I'm moving to dotnet/runtime.
steveisok commentedon Jan 19, 2023
/cc @vargaz
JayToltTech commentedon May 6, 2023
FYI, this makes 'hello world' on iOS fail. For me, this implies that .NET on iOS isn't anyone's priority, given that the most basic of apps fails to launch and it's not being investigated.
jhimes144 commentedon May 6, 2023
Yup. This issue hasn't received any activity for almost 4 months.
steveisok commentedon May 6, 2023
@vargaz https://github.com/AvaloniaUI/Avalonia/blob/0ca03349ba9daef25d6d9e95157caade04bae54f/src/Avalonia.OpenGL/GlBasicInfoInterface.cs#L13 is the spot that's being hit.
steveisok commentedon May 6, 2023
@jhimes144 on android, was full aot being used and you didn't hit this problem? If not, it's very likely the code path was still using jit.
jhimes144 commentedon May 7, 2023
@steveisok Full aot was/is being used on android and the problem is not encountered.
vargaz commentedon May 7, 2023
This particular code pattern, when a function pointer is returned from native code and later called using calli is not supported by full-aot, don't think it ever was. The reason is that the runtime needs to generate a managed-to-native wrapper to call the function pointer, and the wrapper needs to embed the address which is called which is a runtime constant, so it cannot be generated at AOT time.
Enabling the interpreter might fix the problem.
jhimes144 commentedon May 8, 2023
@maxkatz6 Tagging you here
maxkatz6 commentedon May 8, 2023
@vargaz thanks for the explanation.
To summarize, this scenario isn't supported in mono aot currently? I understand that function pointer isn't known in compile time, but it still possible to generate trampoline function with this runtime pointer and parameters.
Either way, we will look into possible workarounds.
But as far as I know the same approach is also used in other OpenGL wrappers for dotnet like Silk.NET
34 remaining items
steveisok commentedon Jun 6, 2023
We landed the fix in main, but the backport to 7 hasn't made it yet. Can you try a .net 8 nightly sdk instead?
nref commentedon Jun 6, 2023
Having trouble building with net8.0.
Process so far:
dotnet-sdk-8.0.100-preview.6.23305.4-win-x64.exe,TargetFrameworkfromnet7.0-iostonet8.0-ios. Didn't touchRuntimeIdentifier, that caused other errors.2>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\16.4.8531-net8-p6\targets\Xamarin.Shared.Sdk.targets(1039,4): error MSB4057: The target "_ComputeManagedAssemblyToLink" does not exist in the project.Googling around points to the linker.
MTouchLink=Nonehad no effect.Out of time for now.
vargaz commentedon Jun 6, 2023
The backport PR is:
#86934
rolfbjarne commentedon Jun 6, 2023
I believe you can work around this by adding this to your csproj:
nref commentedon Jun 6, 2023
Thanks @rolfbjarne .
I added that and now am getting
2>C:\Program Files\dotnet\packs\Microsoft.iOS.Windows.Sdk\16.4.8531-net8-p6\tools\msbuild\iOS\Xamarin.iOS.Common.After.targets(321,3): error : The illink assembly doesn't exist: ''.rolfbjarne commentedon Jun 6, 2023
@slater1 can you try directly from the Mac?
nref commentedon Jun 6, 2023
Ok, sure. After following the steps below, on the mac a vanilla avalonia.xplat project builds and runs in the iOS simulator:
Steps:
dotnet-sdk-8.0.100-preview.4.23260.5-osx-arm64.pkgon the mac, then:Not sure what this means for me using Visual Studio from Windows. Later today I can try this with a real iPhone.
[release/7.0-staging] [mono][aot] Generate 'native-indirect' wrappers…
DrWenz commentedon Jun 21, 2023
i'm facing to the same problem since days, on Simulator it runs perfectly.
I need to put my app in AppStore, what can i do?
nref commentedon Jun 21, 2023
@DrWenz One workaround is to use the mono interpreter.
This worked for me to get my Avalonia iOS app running on real devices. Interpreter is slower sometimes than AOT so be sure to performance test your app.
DrWenz commentedon Jun 21, 2023
Thx @slater1 works like charm :) saved my day!
SamMonoRT commentedon Aug 3, 2023
Based on above comments and backported PR merging, closing this issue. Please re-open if you still encounter the crashes.