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

[.NET 9] iOS notification app extensions #21606

Closed
dottam opened this issue Nov 13, 2024 · 5 comments · Fixed by #21637
Closed

[.NET 9] iOS notification app extensions #21606

dottam opened this issue Nov 13, 2024 · 5 comments · Fixed by #21637
Assignees
Labels
bug If an issue is a bug or a pull request a bug fix regression The issue or pull request is a regression
Milestone

Comments

@dottam
Copy link
Contributor

dottam commented Nov 13, 2024

Apple platform

iOS

Framework version

net9.0-*

Affected platform version

.NET 9.0.100 / iOS MAUI 18.0.9617/9.0.100

Description

The iOS notification extensions does not work as expected in .NET 9, tested on iPhone 12 iOS 18.0.1

Sample project
notification.zip

.NET information

.NET SDK:
Version: 9.0.100
Commit: 59db016f11
Workload version: 9.0.100-manifests.c6f19616
MSBuild version: 17.12.7+5b8665660

Runtime Environment:
OS Name: Mac OS X
OS Version: 15.1
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/9.0.100/

.NET workloads installed:
[maui-ios]
Installation Source: SDK 9.0.100
Manifest Version: 9.0.0/9.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/9.0.100/microsoft.net.sdk.maui/9.0.0/WorkloadManifest.json
Install Type: FileBased

[ios]
Installation Source: SDK 9.0.100
Manifest Version: 18.0.9617/9.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/9.0.100/microsoft.net.sdk.ios/18.0.9617/WorkloadManifest.json
Install Type: FileBased

[maui]
Installation Source: SDK 9.0.100
Manifest Version: 9.0.0/9.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/9.0.100/microsoft.net.sdk.maui/9.0.0/WorkloadManifest.json
Install Type: FileBased

Steps to Reproduce

  1. Change the bundle identifier in the Info.plist for the notificationTest, notificationService and notificationContent sample projects to match your provisioning profile
  2. Build the project
    dotnet build notificationTest/notificationTest.csproj -c Debug -p:Platform="iPhone" -p:RuntimeIdentifier="ios-arm64"
  3. Install and launch the app on device
  4. Tap "Send Local Notification" button
  5. Long pressed the notification to show details

Observe logs from Console app

Did you find any workaround?

Sets the TargetFramework to net8.0-ios in the following projects

  • notificationContent/notificationContent.csproj
  • notificationService/notificationService.csproj

Relevant logs

Logs from Console app:

*** Terminating app due to uncaught exception 'ObjCRuntime.RuntimeException', reason: 'Could not find the type 'ObjCRuntime.Registrar' in the assembly 'NotificationTest.NotificationContent'. (ObjCRuntime.RuntimeException)
at ObjCRuntime.RegistrarHelper.GetMapEntry(String assemblyName)
at ObjCRuntime.RegistrarHelper.GetMapEntry(Assembly assembly)
at ObjCRuntime.RegistrarHelper.LookupRegisteredType(Assembly assembly, UInt32 id)
at ObjCRuntime.Class.ResolveToken(Assembly assembly, Module module, UInt32 token)
at ObjCRuntime.Class.ResolveFullTokenReference(UInt32 token_reference)
at ObjCRuntime.Class.ResolveTokenReference(UInt32 token_reference, UInt32 implicit_token_type)
at ObjCRuntime.Class.ResolveTypeTokenReference(UInt32 token_reference)
at ObjCRuntime.Class.FindType(NativeHandle class, Boolean& is_custom_type)
at ObjCRuntime.Class.Lookup(IntPtr klass, Boolean throw_on_error)
at ObjCRuntime.Class.Lookup(IntPtr klass)
at ObjCRuntime.Runtime.ConstructNSObject(IntPt<…>

Received unhandled Objective-C exception that was marshalled from a managed exception: Could not find the type 'ObjCRuntime.Registrar' in the assembly 'NotificationTest.NotificationContent'. (ObjCRuntime.RuntimeException)
at ObjCRuntime.RegistrarHelper.GetMapEntry(String assemblyName)
at ObjCRuntime.RegistrarHelper.GetMapEntry(Assembly assembly)
at ObjCRuntime.RegistrarHelper.LookupRegisteredType(Assembly assembly, UInt32 id)
at ObjCRuntime.Class.ResolveToken(Assembly assembly, Module module, UInt32 token)
at ObjCRuntime.Class.ResolveFullTokenReference(UInt32 token_reference)
at ObjCRuntime.Class.ResolveTokenReference(UInt32 token_reference, UInt32 implicit_token_type)
at ObjCRuntime.Class.ResolveTypeTokenReference(UInt32 token_reference)
at ObjCRuntime.Class.FindType(NativeHandle class, Boolean& is_custom_type)
at ObjCRuntime.Class.Lookup(IntPtr klass, Boolean throw_on_error)
at ObjCRuntime.Class.Lookup(IntPtr klass)
at ObjCRuntime.Runtime.ConstructNSObject(IntPt<…>

@dottam dottam changed the title [.NET 9 RC2] iOS notification app extensions [.NET 9] iOS notification app extensions Nov 13, 2024
@rolfbjarne
Copy link
Member

Can you try adding this to the csproj to see if that works around it?

<PropertyGroup>
    <Registrar>static</Registrar>
</PropertyGroup>

@rolfbjarne rolfbjarne added this to the Future milestone Nov 13, 2024
@rolfbjarne rolfbjarne added the need-info Waiting for more information before the bug can be investigated label Nov 13, 2024
@dottam
Copy link
Contributor Author

dottam commented Nov 14, 2024

setting Registrar property works. Is this a workaround or we need to add this property moving forward?

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Nov 14, 2024
@rolfbjarne
Copy link
Member

It's a workaround, we'll fix it so that it works without it (although I'm not sure right now when that might be).

@rolfbjarne rolfbjarne added bug If an issue is a bug or a pull request a bug fix regression The issue or pull request is a regression app-extensions and removed need-attention An issue requires our attention/response labels Nov 14, 2024
@rolfbjarne rolfbjarne self-assigned this Nov 14, 2024
@ivanpovazan
Copy link
Contributor

Just for reference and to not lose the track of it.
The linked issue: roubachof/NukeProxy#23 which a potential duplicate, also has a repro project posted here: https://github.com/Cheesebaron/NukeProxyObjCRuntimeRegistrar
/cc: @Cheesebaron

rolfbjarne added a commit that referenced this issue Nov 15, 2024
This is a workaround for #21606, until the managed static registrar is fixed to work with app extensions.
azure-pipelines bot pushed a commit that referenced this issue Nov 15, 2024
This is a workaround for #21606, until the managed static registrar is fixed to work with app extensions.
rolfbjarne added a commit that referenced this issue Nov 18, 2024
…static registrar. Fixes #21606.

If an assembly only required the lookup tables from the managed static
registrar (and not any other code), we wouldn't save those changes.

This would lead to a runtime exception:

```
Microsoft.iOS: Processing Objective-C exception for exception marshalling (mode: 2):
Could not find the type 'ObjCRuntime.__Registrar__' in the assembly 'X.Y.Z'. (ObjCRuntime.RuntimeException)
   at ObjCRuntime.RegistrarHelper.GetMapEntry(String assemblyName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/RegistrarHelper.cs:line 105
   at ObjCRuntime.RegistrarHelper.GetMapEntry(Assembly assembly) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/RegistrarHelper.cs:line 93
   at ObjCRuntime.RegistrarHelper.LookupRegisteredType(Assembly assembly, UInt32 id) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/RegistrarHelper.cs:line 199
   at ObjCRuntime.Class.ResolveToken(Assembly assembly, Module module, UInt32 token) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Class.cs:line 521
```

The fix is to save the assembly if the managed static registrar added lookup
tables to the assembly.

Fixes #21606.
azure-pipelines bot pushed a commit that referenced this issue Nov 18, 2024
…static registrar. Fixes #21606.

If an assembly only required the lookup tables from the managed static
registrar (and not any other code), we wouldn't save those changes.

This would lead to a runtime exception:

```
Microsoft.iOS: Processing Objective-C exception for exception marshalling (mode: 2):
Could not find the type 'ObjCRuntime.__Registrar__' in the assembly 'X.Y.Z'. (ObjCRuntime.RuntimeException)
   at ObjCRuntime.RegistrarHelper.GetMapEntry(String assemblyName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/RegistrarHelper.cs:line 105
   at ObjCRuntime.RegistrarHelper.GetMapEntry(Assembly assembly) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/RegistrarHelper.cs:line 93
   at ObjCRuntime.RegistrarHelper.LookupRegisteredType(Assembly assembly, UInt32 id) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/RegistrarHelper.cs:line 199
   at ObjCRuntime.Class.ResolveToken(Assembly assembly, Module module, UInt32 token) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Class.cs:line 521
```

The fix is to save the assembly if the managed static registrar added lookup
tables to the assembly.

Fixes #21606.
@rolfbjarne
Copy link
Member

I can reproduce the problem, and a fix is in progress.

dalexsoto pushed a commit that referenced this issue Nov 19, 2024
…de by the managed static registrar. Fixes #21606. (#21638)

If an assembly only required the lookup tables from the managed static
registrar (and not any other code), we wouldn't save those changes.

This would lead to a runtime exception:

```
Microsoft.iOS: Processing Objective-C exception for exception marshalling (mode: 2):
Could not find the type 'ObjCRuntime.__Registrar__' in the assembly 'X.Y.Z'. (ObjCRuntime.RuntimeException)
   at ObjCRuntime.RegistrarHelper.GetMapEntry(String assemblyName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/RegistrarHelper.cs:line 105
   at ObjCRuntime.RegistrarHelper.GetMapEntry(Assembly assembly) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/RegistrarHelper.cs:line 93
   at ObjCRuntime.RegistrarHelper.LookupRegisteredType(Assembly assembly, UInt32 id) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/RegistrarHelper.cs:line 199
   at ObjCRuntime.Class.ResolveToken(Assembly assembly, Module module, UInt32 token) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Class.cs:line 521
```

The fix is to save the assembly if the managed static registrar added
lookup
tables to the assembly.

Fixes #21606.


Backport of #21637

---------

Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug If an issue is a bug or a pull request a bug fix regression The issue or pull request is a regression
Projects
None yet
3 participants