maui icon indicating copy to clipboard operation
maui copied to clipboard

Reproducible Crash iOS AOT GlobalizationNative_LoadICUData

Open usertoroot opened this issue 1 year ago • 1 comments

Description

I am not sure if it should be on runtime or here so this is posted on both (see https://github.com/dotnet/runtime/issues/97599).

iOS app crashes instantly when SayHello is called. I have isolated it to the .ToString() call on the double object.

MacOS: Sonoma 14.2.1 iOS Swift Deployment Target: 15.2 Xcode: 15.2 Dotnet 8.0.101 o maui-ios 8.0.3/8.0.100 o maui 8.0.3/8.0.100 o mobile-librarybuilder 8.0.1/8.0.100

Here is the stack trace.

image

Desired behavior:

  1. It should not crash
  2. The interpreter should not be used when disabled

Steps to Reproduce

On the C# side

Program.cs

using System;
using System.Runtime.InteropServices;

namespace ManagedProject
{
    unsafe class Program
    {
        [UnmanagedCallersOnly(EntryPoint = nameof(SayHello))]
        public static int SayHello(int a, int b)
        {
            //return ThisFunctionWorks(a, b);
            return (int)ThisFunctionCrashes(a, b);
        }

        public static int ThisFunctionWorks(int a, int b)
        {
            Console.WriteLine($"sum1({a}, {b})");
            return a + b;
        }

        public static double ThisFunctionCrashes(double a, double b)
        {
            Console.WriteLine($"sum2({a}, {b})"); //<- crash on this line (due to .ToString)
            return (double)(a + b);
        }

        public static void Main(string[] args)
        {

        }
    }
}

ManagedProject.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>    
    <SelfContained>True</SelfContained>
    <NativeLib>Shared</NativeLib>
    <RunAOTCompilation>True</RunAOTCompilation>
    <ForceFullAOT>True</ForceFullAOT>
    <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
    <UseInterpreter>False</UseInterpreter>
    <StaticICULinking>True</StaticICULinking>
    <MtouchLink>None</MtouchLink>
  </PropertyGroup>

  <ItemGroup>
    <!-- Preserves the UnmanagedCallersOnly method -->
    <TrimmerRootDescriptor Include="$(MSBuildThisFileDirectory)ILLink.Descriptor.xml" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="System.Globalization" Version="4.3.0" />
  </ItemGroup>
</Project>

ILLink.Descriptor.xml

<linker>
  <assembly fullname="ManagedProject">
    <type fullname="ManagedProject.Program">
      <method name="SayHello" />
    </type>
  </assembly>
</linker>

On the Swift side just a empty SwiftUI project with the following ContentView

import SwiftUI
import Pan

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")

        }
        .padding()
        .onAppear(perform: {
            let c = SayHello(1, 2)
            print("test \(c)")
        })
    }
}

#Preview {
    ContentView()
}

And bridging header Cs-Bridging-Header.h

#ifndef Cs_Bridging_Header_h
#define Cs_Bridging_Header_h
int SayHello(int a, int b);
#endif

Link to public reproduction project repository

No response

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

usertoroot avatar Jan 27 '24 17:01 usertoroot

Duplicate of https://github.com/dotnet/runtime/issues/97599

jkotas avatar Jan 27 '24 23:01 jkotas

Yeah, this is a Runtime issue, closing as duplicate of https://github.com/dotnet/runtime/issues/97599

drasticactions avatar Jan 29 '24 11:01 drasticactions