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
Default RID is always x64, even on arm64 machines #17841
Comments
Why this matters? Because if you are using an app or library with a binding to a native framework, and you launch your app in Visual Studio for Mac on an arm64 machine, it tries builds for x64 and then throws an exception when trying to use a component from the native framework. For example, using Sentry.Maui will give this exception on initialization: Exception details are specific to that library, but the key point is If you manually set the RID for |
Also, I think my "workaround" is problematic because it will then build using |
This isn't entirely accurate: building for x64 should work just fine on an arm64 (if you have Rosetta installed), the app will be an x64 app, using x64 native libraries. The only problem could be if the NuGet doesn't provide an x64 version of the native library (but in that case the NuGet wouldn't work on an x64 machine). So if a NuGet isn't working when building for x64 on an arm64 machine, something else is wrong. In any case the plan is currently to change the default for .NET 8.
Correct, it won't work properly if you build for device in the IDE. This is because the default RuntimeIdentifier is actually overridden by the IDE when building in the IDE (to whatever device/simulator you're building for) - but you're overriding the default, and thus also overriding what the IDE does. AFAIK there's currently no trivial way to do what you want (force a RuntimeIdentifier for simulator only), but you might be able to create a custom configuration that does it, something like this: <PropertyGroup Condition="'$(Configuration)' == 'DebugSimulator'">
<RuntimeIdentifier>iossimulator-arm64</RuntimeIdentifier>
</PropertyGroup> and then selecting the DebugSimulator configuration in the IDE when you want to debug in the simulator. |
Actually, I wonder if this would work: <OSArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</OSArchitecture>
<RuntimeIdentifier Condition="'$(OSArchitecture)' == 'Arm64' And '$(RuntimeIdentifier)' == 'iossimulator-x64'">iossimulator-arm64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(OSArchitecture)' == 'X64'">iossimulator-x64</RuntimeIdentifier> which looks a bit weird, but the idea is that if the IDE has set RuntimeIdentifier=iossimulator-x64, and we're on arm64, then change RuntimeIdentifier to |
I tried that - it doesn't work in the default case when the |
Slight tweak, this seems to work for me: <OSArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</OSArchitecture>
<RuntimeIdentifier Condition="'$(OSArchitecture)' == 'Arm64' And '$(_iOSRuntimeIdentifier)' == 'iossimulator-x64'">iossimulator-arm64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(OSArchitecture)' == 'X64'">iossimulator-x64</RuntimeIdentifier> |
Good call on <PropertyGroup>
<_OSArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</_OSArchitecture>
<_TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</_TargetPlatformIdentifier>
<RuntimeIdentifier Condition="'$(_TargetPlatformIdentifier)' == 'ios' And '$(_OSArchitecture)' == 'Arm64' And ('$(_iOSRuntimeIdentifier)' == 'iossimulator-x64' Or ('$(_iOSRuntimeIdentifier)' == '' And '$(RuntimeIdentifier)' == ''))">iossimulator-arm64</RuntimeIdentifier>
</PropertyGroup> (No need to set x64, since that would be correct already.) Also note - This has to be in the app's csproj, after the target framework is set. Ideally it would be in |
Hmmm.. Well, the native libraries are like this: There's only two versions - either Is it possible that the arm64 code from the fat library was loaded, and then we get the error because we targeted |
Yes, that looks correct :/ In any case, we'll change the default RID for .NET 8, and in the meantime I believe you have a viable workaround. |
@rolfbjarne this solution doesn't work for me as I am using AppCenter and it doesnot have simulator slice in .a file. I am still stucked |
It would be great if this was fixed for .NET 6+, since they're still in their support lifecycle. I believe it's in this section? Thanks. |
It's a rather big change, and will break some people, because there are a lot of third-party native libraries that don't ship an arm64 slice for the simulator, which is why we will only do this starting with .NET 8. |
You might be running into a different problem, so I suggest filing a new issue (to avoid making things confusing here), and we can diagnose your problem there. |
* When publishing a mobile app, choose a device architecture (as opposed to showing an error if none was specified by the developer) * When building for the simulator, choose the arm64 runtime identifier if we're running on an arm64 machine. * When building a Debug build for desktop, choose the arm64 runtime identifier if we're running on an arm64 machine. Fixes #18455. Fixes #16152. Fixes #17841. Section in the release notes: https://github.com/xamarin/xamarin-macios/wiki/.NET-8-release-notes#default-runtimeidentifiers --------- Co-authored-by: Alex Soto <alex@alexsoto.me>
Fixed in #18495. |
Steps to Reproduce
(Or a MAUI app targeting iOS, etc.)
Expected Behavior
iossimulator-x64
iossimulator-arm64
Actual Behavior
It always builds using
iossimulator-x64
(Note, the same is true for Mac Catalyst targets. It always builds for
maccatalyst-x64
.)Workaround
Add to the csproj:
(This shouldn't be necessary though.)
Environment
Version information
Build Logs
log.binlog.zip
Example Project (If Possible)
IosApp1.zip
The text was updated successfully, but these errors were encountered: