Skip to content
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

NativeAOT compilation issue on IOS ARM64 - losing interface members? #92106

Closed
charlesroddie opened this issue Sep 15, 2023 · 25 comments
Closed
Assignees
Milestone

Comments

@charlesroddie
Copy link

Description

We have an interface IPlatformData defined in project A, and an App type, with some diagnostic Console.Writelines.

type IPlatformData =
    abstract member OS: OS
    abstract member DeviceType: DeviceType
    /// The number of pixels for each XF unit on the device
    abstract member DpiScaling: ISignal<float32<pixel>>
    ...

type App(ipd: IPlatformData) = ...
    Console.WriteLine("A OS: " + ipd.OS.ToString())
    Console.WriteLine("A DeviceType: " + ipd.DeviceType.ToString())

This is referenced by an IOS project, project B. There is an implementation:

public class IOSPlatformData: IPlatformData
{
    public OS OS => OS.IOS;
    public PlatformType.DeviceType DeviceType => ...
    public ISignal<float> DpiScaling => Signal.constant((float)UIScreen.MainScreen.Scale);
    ...

The Magic

When project B calls no interface properties directly, the app crashes in "A OS: " + ipd.OS.ToString():

var iosPd = new IOSPlatformData();
var app = new App(iosPd);

When project B calls iosPd.OS properties directly, the previous line succeeds and the app prints A OS: IOS and crashes in "A DeviceType: " + ipd.DeviceType.ToString():

var iosPd = new IOSPlatformData();
Console.WriteLine("B OS: " + iosPd.OS.ToString())
var app = new App(iosPd);

When project B calls both properties directly, the previous line also succeeds and the app prints A OS: IOS and A DeviceType: IPad:

var iosPd = new IOSPlatformData();
Console.WriteLine("B OS: " + iosPd.OS.ToString());
Console.WriteLine("B DeviceType: " + iosPd.DeviceType.ToString());
var app = new App(iosPd);

It seems like interface properties are getting stripped unless they are referenced in Project B and there is a failure to detect usage from Project A.

We got one stacktrace which immediately goes from our code (line 7) into low level NativeAOT ARM64 stuff (0-6).

Thread 0 Crashed:
0   libsystem_kernel.dylib          0x00000001db681578 __pthread_kill + 8 (:-1)
1   libsystem_pthread.dylib         0x00000001fc381118 pthread_kill + 268 (pthread.c:1670)
2   libsystem_c.dylib               0x00000001a44ec178 abort + 180 (abort.c:118)
3   50iOS                           0x0000000102dab6c4 ReleaseCondAttr(_opaque_pthread_condattr_t*) + 947908 (PalRedhawkUnix.cpp:122)
4   50iOS                           0x0000000103371f38 fram0_S_P_CoreLib_System_Runtime_CachedInterfaceDispatch__RhpCidResolve_Worker + 136
5   50iOS                           0x0000000103371ea0 S_P_CoreLib_System_Runtime_CachedInterfaceDispatch__RhpCidResolve + 16
6   50iOS                           0x0000000102dbad20 RhpUniversalTransition_DebugStepTailCall + 60
7   50iOS                           0x0000000103617bac fram0__41ViewModels__StartupCode_41ViewModels___Device___cctor + 9780140 (Device.fs:17)

Reproduction Steps

We don't yet have a minimal reproduction. We will try to get this when our developer with the mac is back online next week.

Expected behavior

All the writelines succeed and the app doesn't crash at any point.

Actual behavior

As above

Regression?

No response

Known Workarounds

No response

Configuration

Running on fairly modern iPads, ARM64, latest IOS.

Compiled on

Agent name: 'Azure Pipelines 3'
Agent machine name: 'Mac-1694710320803'
Current agent version: '3.225.0'
Operating System
Runner Image
Image: macos-13
Version: 20230903.1
Included Software: https://github.com/actions/runner-images/blob/macos-13/20230903.1/images/macos/macos-13-Readme.md
Image Release: https://github.com/actions/runner-images/releases/tag/macos-13%2F20230903.1

Build process includes referencing dotnet8 in the project, and this was tested post-RC1 release. The pipeline contains "Use .NET Core sdk 8.x" and dotnet publish. We haven't yet reproduced when compiling from mac.

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Sep 15, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 15, 2023
@ghost
Copy link

ghost commented Sep 15, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

We have an interface IPlatformData defined in project A, and an App type, with some diagnostic Console.Writelines.

type IPlatformData =
    abstract member OS: OS
    abstract member DeviceType: DeviceType
    /// The number of pixels for each XF unit on the device
    abstract member DpiScaling: ISignal<float32<pixel>>
    ...

type App(ipd: IPlatformData) = ...
    Console.WriteLine("A OS: " + ipd.OS.ToString())
    Console.WriteLine("A DeviceType: " + ipd.DeviceType.ToString())

This is referenced by an IOS project, project B. There is an implementation:

public class IOSPlatformData: IPlatformData
{
    public OS OS => OS.IOS;
    public PlatformType.DeviceType DeviceType => ...
    public ISignal<float> DpiScaling => Signal.constant((float)UIScreen.MainScreen.Scale);
    ...

The Magic

When project B calls no interface properties directly, the app crashes in "A OS: " + ipd.OS.ToString():

var iosPd = new IOSPlatformData();
var app = new App(iosPd);

When project B calls iosPd.OS properties directly, the previous line succeeds and the app prints A OS: IOS and crashes in "A DeviceType: " + ipd.DeviceType.ToString():

var iosPd = new IOSPlatformData();
Console.WriteLine("B OS: " + iosPd.OS.ToString())
var app = new App(iosPd);

When project B calls both properties directly, the previous line also succeeds and the app prints A OS: IOS and A DeviceType: IPad:

var iosPd = new IOSPlatformData();
Console.WriteLine("B OS: " + iosPd.OS.ToString());
Console.WriteLine("B DeviceType: " + iosPd.DeviceType.ToString());
var app = new App(iosPd);

It seems like interface properties are getting stripped unless they are referenced in Project B and there is a failure to detect usage from Project A.

We got one stacktrace which immediately goes from our code (line 7) into low level NativeAOT ARM64 stuff (0-6).

Thread 0 Crashed:
0   libsystem_kernel.dylib          0x00000001db681578 __pthread_kill + 8 (:-1)
1   libsystem_pthread.dylib         0x00000001fc381118 pthread_kill + 268 (pthread.c:1670)
2   libsystem_c.dylib               0x00000001a44ec178 abort + 180 (abort.c:118)
3   50iOS                           0x0000000102dab6c4 ReleaseCondAttr(_opaque_pthread_condattr_t*) + 947908 (PalRedhawkUnix.cpp:122)
4   50iOS                           0x0000000103371f38 fram0_S_P_CoreLib_System_Runtime_CachedInterfaceDispatch__RhpCidResolve_Worker + 136
5   50iOS                           0x0000000103371ea0 S_P_CoreLib_System_Runtime_CachedInterfaceDispatch__RhpCidResolve + 16
6   50iOS                           0x0000000102dbad20 RhpUniversalTransition_DebugStepTailCall + 60
7   50iOS                           0x0000000103617bac fram0__41ViewModels__StartupCode_41ViewModels___Device___cctor + 9780140 (Device.fs:17)

Reproduction Steps

We don't yet have a minimal reproduction. We will try to get this when our developer with the mac is back online next week.

Expected behavior

All the writelines succeed and the app doesn't crash at any point.

Actual behavior

As above

Regression?

No response

Known Workarounds

No response

Configuration

Running on fairly modern iPads, ARM64, latest IOS.

Compiled on

Agent name: 'Azure Pipelines 3'
Agent machine name: 'Mac-1694710320803'
Current agent version: '3.225.0'
Operating System
Runner Image
Image: macos-13
Version: 20230903.1
Included Software: https://github.com/actions/runner-images/blob/macos-13/20230903.1/images/macos/macos-13-Readme.md
Image Release: https://github.com/actions/runner-images/releases/tag/macos-13%2F20230903.1

Build process includes referencing dotnet8 in the project, and this was tested post-RC1 release. The pipeline contains "Use .NET Core sdk 8.x" and dotnet publish. We haven't yet reproduced when compiling from mac.

Other information

No response

Author: charlesroddie
Assignees: -
Labels:

untriaged, area-NativeAOT-coreclr, needs-area-label

Milestone: -

@jkotas jkotas removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Sep 15, 2023
@jkotas
Copy link
Member

jkotas commented Sep 15, 2023

Likely duplicate of #90333 that is fixed in .NET 8 RC2.

Could you please try latest .NET 8 RC2 build? You can either install latest .NET 8 SDK RC2 from https://github.com/dotnet/installer, or upgrade just the native AOT package using instructions at https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/compiling.md#using-daily-builds.

@jkotas jkotas added the needs-author-action An issue or pull request that requires more info or actions from the author. label Sep 15, 2023
@ghost
Copy link

ghost commented Sep 15, 2023

This issue has been marked needs-author-action and may be missing some important information.

@charlesroddie
Copy link
Author

charlesroddie commented Sep 17, 2023

Thanks. We'll definitely want to be using the latest bits for our testing to be worthwhile.

It took 32 attempts but we got .NET 8 SDK RC2 installing in Azure Devops.

Subsequently we need to install the maui workload in order to allow the dotnet-ios build. Using

dotnet workload install maui-ios --source https://api.nuget.org/v3/index.json --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json'

fails with

Installing workload manifest microsoft.net.sdk.android version 34.0.0-rc.2.442...
Installing workload manifest microsoft.net.sdk.ios version 17.0.8314-ci.release-test-net8-0-xcode15-multi-targeting...
Installing workload manifest microsoft.net.sdk.maccatalyst version 17.0.8314-ci.release-test-net8-0-xcode15-multi-targeting...
Installing workload manifest microsoft.net.sdk.macos version 14.0.8314-ci.release-test-net8-0-xcode15-multi-targeting...
Installing workload manifest microsoft.net.sdk.maui version 8.0.0-nightly.9210...
Installing workload manifest microsoft.net.sdk.tvos version 17.0.8314-ci.release-test-net8-0-xcode15-multi-targeting...
Installing workload manifest microsoft.net.workload.mono.toolchain.current version 8.0.0-rc.2.23466.4...
Installing workload manifest microsoft.net.workload.emscripten.current version 8.0.0-rc.2.23465.1...
Installing workload manifest microsoft.net.workload.emscripten.net6 version 8.0.0-rc.2.23465.1...
Installing workload manifest microsoft.net.workload.emscripten.net7 version 8.0.0-rc.2.23465.1...
Installing workload manifest microsoft.net.workload.mono.toolchain.net6 version 8.0.0-rc.2.23466.4...
Installing workload manifest microsoft.net.workload.mono.toolchain.net7 version 8.0.0-rc.2.23466.4...
Installing pack Microsoft.AspNetCore.Components.WebView.Maui version 8.0.0-nightly.9210...
Writing workload pack installation record for Microsoft.AspNetCore.Components.WebView.Maui version 8.0.0-nightly.9210...
Installing pack Microsoft.Maui.Sdk version 8.0.0-nightly.9210...
Writing workload pack installation record for Microsoft.Maui.Sdk.net8 version 8.0.0-nightly.9210...
Installing pack Microsoft.Maui.Sdk version 7.0.92...
Writing workload pack installation record for Microsoft.Maui.Sdk.net7 version 7.0.92...
Installing pack Microsoft.Maui.Graphics version 8.0.0-nightly.9210...
Writing workload pack installation record for Microsoft.Maui.Graphics version 8.0.0-nightly.9210...
Installing pack Microsoft.iOS.Sdk.net8.0_17.0 version 17.0.8314-ci.release-test-net8-0-xcode15-multi-targeting...
Writing workload pack installation record for Microsoft.iOS.Sdk.net8.0_17.0 version 17.0.8314-ci.release-test-net8-0-xcode15-multi-targeting...
Installing pack Microsoft.iOS.Sdk.net7.0_16.0 version 16.0.1498-ci.release-test-multi-targetting-7-0-1xx-xcode14...
Workload installation failed. Rolling back installed packs...
...
Workload installation failed: microsoft.ios.sdk.net7.0_16.0::16.0.1498-ci.release-test-multi-targetting-7-0-1xx-xcode14 is not found in NuGet feeds https://api.nuget.org/v3/index.json;https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json".
##[error]Error: The process '/usr/local/bin/dotnet' failed with exit code 1
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects : [ '' ]

It seems to be getting confused with both net7 and net8 references present.

@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Sep 17, 2023
@jkotas jkotas added the os-ios Apple iOS label Sep 18, 2023
@ghost
Copy link

ghost commented Sep 18, 2023

Tagging subscribers to 'os-ios': @steveisok, @akoeplinger, @kotlarmilos
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

We have an interface IPlatformData defined in project A, and an App type, with some diagnostic Console.Writelines.

type IPlatformData =
    abstract member OS: OS
    abstract member DeviceType: DeviceType
    /// The number of pixels for each XF unit on the device
    abstract member DpiScaling: ISignal<float32<pixel>>
    ...

type App(ipd: IPlatformData) = ...
    Console.WriteLine("A OS: " + ipd.OS.ToString())
    Console.WriteLine("A DeviceType: " + ipd.DeviceType.ToString())

This is referenced by an IOS project, project B. There is an implementation:

public class IOSPlatformData: IPlatformData
{
    public OS OS => OS.IOS;
    public PlatformType.DeviceType DeviceType => ...
    public ISignal<float> DpiScaling => Signal.constant((float)UIScreen.MainScreen.Scale);
    ...

The Magic

When project B calls no interface properties directly, the app crashes in "A OS: " + ipd.OS.ToString():

var iosPd = new IOSPlatformData();
var app = new App(iosPd);

When project B calls iosPd.OS properties directly, the previous line succeeds and the app prints A OS: IOS and crashes in "A DeviceType: " + ipd.DeviceType.ToString():

var iosPd = new IOSPlatformData();
Console.WriteLine("B OS: " + iosPd.OS.ToString())
var app = new App(iosPd);

When project B calls both properties directly, the previous line also succeeds and the app prints A OS: IOS and A DeviceType: IPad:

var iosPd = new IOSPlatformData();
Console.WriteLine("B OS: " + iosPd.OS.ToString());
Console.WriteLine("B DeviceType: " + iosPd.DeviceType.ToString());
var app = new App(iosPd);

It seems like interface properties are getting stripped unless they are referenced in Project B and there is a failure to detect usage from Project A.

We got one stacktrace which immediately goes from our code (line 7) into low level NativeAOT ARM64 stuff (0-6).

Thread 0 Crashed:
0   libsystem_kernel.dylib          0x00000001db681578 __pthread_kill + 8 (:-1)
1   libsystem_pthread.dylib         0x00000001fc381118 pthread_kill + 268 (pthread.c:1670)
2   libsystem_c.dylib               0x00000001a44ec178 abort + 180 (abort.c:118)
3   50iOS                           0x0000000102dab6c4 ReleaseCondAttr(_opaque_pthread_condattr_t*) + 947908 (PalRedhawkUnix.cpp:122)
4   50iOS                           0x0000000103371f38 fram0_S_P_CoreLib_System_Runtime_CachedInterfaceDispatch__RhpCidResolve_Worker + 136
5   50iOS                           0x0000000103371ea0 S_P_CoreLib_System_Runtime_CachedInterfaceDispatch__RhpCidResolve + 16
6   50iOS                           0x0000000102dbad20 RhpUniversalTransition_DebugStepTailCall + 60
7   50iOS                           0x0000000103617bac fram0__41ViewModels__StartupCode_41ViewModels___Device___cctor + 9780140 (Device.fs:17)

Reproduction Steps

We don't yet have a minimal reproduction. We will try to get this when our developer with the mac is back online next week.

Expected behavior

All the writelines succeed and the app doesn't crash at any point.

Actual behavior

As above

Regression?

No response

Known Workarounds

No response

Configuration

Running on fairly modern iPads, ARM64, latest IOS.

Compiled on

Agent name: 'Azure Pipelines 3'
Agent machine name: 'Mac-1694710320803'
Current agent version: '3.225.0'
Operating System
Runner Image
Image: macos-13
Version: 20230903.1
Included Software: https://github.com/actions/runner-images/blob/macos-13/20230903.1/images/macos/macos-13-Readme.md
Image Release: https://github.com/actions/runner-images/releases/tag/macos-13%2F20230903.1

Build process includes referencing dotnet8 in the project, and this was tested post-RC1 release. The pipeline contains "Use .NET Core sdk 8.x" and dotnet publish. We haven't yet reproduced when compiling from mac.

Other information

No response

Author: charlesroddie
Assignees: -
Labels:

untriaged, os-ios, area-NativeAOT-coreclr

Milestone: -

@jkotas
Copy link
Member

jkotas commented Sep 18, 2023

@ivanpovazan What is the best way to try daily .NET 8 RC2 build on iOS with native AOT?

@ivanpovazan
Copy link
Member

@charlesroddie could you please try to include net7.0 feed as well, so that the workload installation command would look like:

dotnet workload install maui-ios --source https://api.nuget.org/v3/index.json --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json

That should fix the errors you are seeing. The reason why workload installation also pulls in net7.0 references is to ensure building projects configured with TargetFrameworks=net7.0-ios works out-of-the-box.

As an additional note, making the current preview release properly set up is unfortunately a struggle at the moment. If I am not mistaken the latest nightly release seems to be referencing Xcode 15 beta iOS builds which in turn require an upgrade of Xcode in order to build projects.

/cc: @rolfbjarne

@ivanpovazan
Copy link
Member

ivanpovazan commented Sep 18, 2023

One more thing you can try - if you only want to verify what @jkotas suggested works:

Likely duplicate of #90333 that is fixed in .NET 8 RC2.

Could you please try latest .NET 8 RC2 build? You can either install latest .NET 8 SDK RC2 from https://github.com/dotnet/installer, or upgrade just the native AOT package using instructions at https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/compiling.md#using-daily-builds.

Do the following instead:

  1. Install the official RC1 release from: https://dotnet.microsoft.com/en-us/download/dotnet/8.0
  2. Install maui workloads:
dotnet workload install maui-ios
  1. Edit your iOS project file to include RC2 NativeAOT compiler and the runtime with:
<ItemGroup>
    <FrameworkReference Update="Microsoft.NETCore.App" RuntimeFrameworkVersion="8.0.0-rc.2.23464.16" />
    <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="8.0.0-rc.2.23464.16" />
</ItemGroup>
<PropertyGroup>
     <!-- This is required to fetch RC2 builds with nuget and is equivalent to providing the feed in nuget.config file -->
     <RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json</RestoreAdditionalProjectSources>
</PropertyGroup>
  1. Build/run your app with:
dotnet publish -c Release -r ios-arm64 -p:PublishAot=true -p:PublishAotUsingRuntimePack=true -t:Run

@charlesroddie
Copy link
Author

charlesroddie commented Sep 18, 2023

Thanks! That resolves the build issues. XCode 15 is on the Azure Devops build agents already so that wasn't a problem. Oddly I had to add <EnablePreviewFeatures>True</EnablePreviewFeatures> to avoid errors like
error CA2252: Using 'UIWindow' requires opting into preview features. See https://aka.ms/dotnet-warnings/preview-features for more information.

We still get the crash on startup and when our developer with the mac is back tomorrow we can look at the logs to see if it is the same issue. It's possible that it is since the threads linked to the fix above mention default interface methods and static interface types and we don't use either of those.

@kevcrooks
Copy link

Here's the link to the latest minimal case that @charlesroddie and I have been able to get so far: https://github.com/SummaticLtd/iosAppMinimal

I believe that using the preview features has resulted in a failure earlier on in the execution than was initially stated though. Now the AppDelegate is not being linked correctly, which is only picked up at runtime.

@ivanpovazan
Copy link
Member

@kevcrooks @charlesroddie thank you for providing the sample project, I will try to repro and get back to you.

@ivanpovazan ivanpovazan self-assigned this Sep 21, 2023
@charlesroddie
Copy link
Author

The current failure is

*** Terminating app due to uncaught exception 'ObjCRuntime.RuntimeException', reason: 'Can't register the class Summatic.iOS.AppDelegate when the dynamic registrar has been linked away. (ObjCRuntime.RuntimeException)
   at ObjCRuntime.Class.GetClassHandle(Type, Boolean, Boolean&) + 0x1c4
   at UIKit.UIApplication.Main(String[], Type, Type) + 0x8c
   at Summatic.iOS.Application.Main(String[]) + 0x64
   at 50iOS!<BaseAddress>+0x1c8821c

@filipnavara I saw a thread where you used the words "linker" and "xcode 15" so tagging you here.

@ivanpovazan
Copy link
Member

*** Terminating app due to uncaught exception 'ObjCRuntime.RuntimeException', reason: 'Can't register the class Summatic.iOS.AppDelegate when the dynamic registrar has been linked away. (ObjCRuntime.RuntimeException)
   at ObjCRuntime.Class.GetClassHandle(Type, Boolean, Boolean&) + 0x1c4
   at UIKit.UIApplication.Main(String[], Type, Type) + 0x8c
   at Summatic.iOS.Application.Main(String[]) + 0x64
   at 50iOS!<BaseAddress>+0x1c8821c

I managed to reproduce your issue. There seems to be an issue with rooting the main assembly with ILLink through <TrimmerRootDescriptor Include="Roots.xml" /> and how the managed static registrar works.

  • As a workaround, could you try removing the following piece from your project file:
	<ItemGroup>
		<TrimmerRootDescriptor Include="Roots.xml" />
	</ItemGroup>
  • As a follow-up I will post a fix to the issue as soon as possible and let you know.

@charlesroddie
Copy link
Author

charlesroddie commented Sep 22, 2023

Thanks! Trying now. Re: TrimmerRootDescriptor, I believe we added this as an attempt to fix the original issue in this thread and have no reason to believe now that we would find it useful.

@ivanpovazan ivanpovazan removed the untriaged New issue has not been triaged by the area owner label Sep 25, 2023
@ivanpovazan ivanpovazan added this to the 8.0.0 milestone Sep 25, 2023
@charlesroddie
Copy link
Author

Likely duplicate of #90333 that is fixed in .NET 8 RC2.

Could you please try latest .NET 8 RC2 build? You can either install latest .NET 8 SDK RC2 from https://github.com/dotnet/installer, or upgrade just the native AOT package using instructions at https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/compiling.md#using-daily-builds.

I can confirm that the original issue is still present in 8.0.100-rtm.23470.21. It has slightly changed in that the loss of individual members doesn't seem to be there but rather we don't successfully get any properties of the class implementing the interface even when accessing from the same project.

@ivanpovazan
Copy link
Member

Would it be possible for you to update the sample project: https://github.com/SummaticLtd/iosAppMinimal in a way that reproduces the new behaviour and crashes?

@charlesroddie
Copy link
Author

charlesroddie commented Sep 27, 2023

Updated the repo. We can confirm that it crashes after adding an interface and using it.

The logs say ѪCWL: About to print DeviceType indicating that the original issue is there and unchanged.

@charlesroddie
Copy link
Author

Able to reproduce @ivanpovazan ?

@ivanpovazan
Copy link
Member

@charlesroddie I am sorry for the delay, but I won't be able to try it out before tomorrow as I am out of office. I will post an update as soon as possible. Thank you for understanding.

@ivanpovazan
Copy link
Member

I managed to reproduce the originally reported issue with the provided repro project and it seems that the issue is related to the default TrimMode being used when compiling apps for NativeAOT on iOS.

With the default setting: TrimMode=full for NativeAOT compilation - ILLinker does not properly mark properties accessed through interfaces and trims them away (it is possible this only happens in this specific setting - when the access through interface is defined in a different assembly). This can be seen when inspecting Summatic.iOS.PlatformData type in obj/Release/net8.0-ios/ios-arm64/linked/50iOS.dll with and without explicitly referencing the DeviceType property, where the linker completely removes the said property.


@charlesroddie to unblock your progress on this, as a workaround, could you try setting in 50iOS.csproj project file:

<TrimMode>partial</TrimMode>

and I will look into properly fixing this in the linker.

@ivanpovazan
Copy link
Member

As suspected:

ILLinker does not properly mark properties accessed through interfaces and trims them away (it is possible this only happens in this specific setting - when the access through interface is defined in a different assembly).

This only seem to happen when referencing a F# library. We have opened #93008 to track fixing this with ILLinker.

@ivanpovazan
Copy link
Member

I just rebuilt and ran the app with dotnet 9.0.0-alpha.1.23531.4 which includes the fix: 6936887 and the app properly outputs:

2023-11-01 17:50:30.697 50iOS[9908:4555366] ѪCWL: Starting MAIN
2023-11-01 17:50:30.710 50iOS[9908:4555366] ѪCWL: Starting FinishedLaunching
2023-11-01 17:50:30.718 50iOS[9908:4555366] ѪCWL: Getting PlatformData
2023-11-01 17:50:30.718 50iOS[9908:4555366] ѪCWL: Getting OS
2023-11-01 17:50:30.718 50iOS[9908:4555366] ѪCWL: Logging OS
2023-11-01 17:50:30.718 50iOS[9908:4555366] ѪCWL: OS: IOS
2023-11-01 17:50:30.718 50iOS[9908:4555366] ѪCWL: Passing in
2023-11-01 17:50:30.718 50iOS[9908:4555366] ѪCWL: About to print OS
2023-11-01 17:50:30.718 50iOS[9908:4555366] ѪCWL: IOS
2023-11-01 17:50:30.718 50iOS[9908:4555366] ѪCWL: About to print DeviceType
2023-11-01 17:50:30.719 50iOS[9908:4555366] ѪCWL: Phone
2023-11-01 17:50:30.719 50iOS[9908:4555366] ѪCWL: Ending FinishedLaunching
  Application 'com.summatic.ios' terminated (with exit code '0' and/or crashing signal ').

As this seems to be fixed I am closing the issue.
Please feel free to reopen it if there are any other concerns.

@kevcrooks
Copy link

@ivanpovazan please could you share info on the steps we need to follow to compile?

I've installed the following dotnet sdk: 9.0.100-alpha.1.23559.1 and compiled (dotnet publish) with the updated global.json file, however the app is still crashing after the line:
ѪCWL: About to print DeviceType

Is there another step we need?

@ivanpovazan
Copy link
Member

@kevcrooks setting up the alpha release is a bit tricky, I can look into how to set it up with the latest version and come back to you.
On the other hand, per our discussion on Discord, we will try to get the fix into the .NET8 servicing release so you wouldn't have to rely on the alpha versions.

@charlesroddie
Copy link
Author

@ivanpovazan our app seems to be working fine on dotnet8 nativeaot with workarounds to interfaces defined in F# and implemented in C#. So we should be OK until the servicing release. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants