XPC crashes while using .net7 and/or .net8
- Dominant language
- C#
- Stars
- 2.9k
- Forks
- 576
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 123
Description
XPC Service does not work on .net7/8 and crashes in runtime with an NSXPCDecoder exception
The same code works fine when targeting .net framework 4.7.2
### Steps to Reproduce
1. Build and run the attached sample code. The repro code provides a bare minimum skeleton for running an XPC service using .net7 or .net8
2. To properly sign the project you might need to make some tweaks, since signing is broken for xpc (see the readme file with instructions)
3. Run the project
4. The exception will be thrown and available in the Console app
### Expected Behavior
The XPC Service should receive a Ping call from the main app
### Actual Behavior
The XPC Service crashes with a runtime exception
```
connection from pid 458 on anonymousListener or serviceListener: Exception caught during decoding of received selector ping, dropping incoming message.
Exception: received a message or reply block that is not in the interface of the remote object (ping), dropping.
(
0 CoreFoundation 0x000000019bac5138 __exceptionPreprocess + 240
1 libobjc.A.dylib 0x000000019b80fe04 objc_exception_throw + 60
2 Foundation 0x000000019cbc84fc -[NSXPCDecoder __decodeXPCObject:allowingSimpleMessageSend:outInvocation:outArguments:outArgumentsMaxCount:outMethodSignature:outSelector:isReply:replySelector:] + 1472
3 Foundation 0x000000019cbc7eb0 -[NSXPCDecoder _decodeMessageFromXPCObject:allowingSimpleMessageSend:outInvocation:outArguments:outArgumentsMaxCount:outMethodSignature:outSelector:] + 44
4 Foundation 0x000000019c9310a0 -[NSXPCConnection _decodeAndInvokeMessageWithEvent:flags:] + 348
5 Foundation 0x000000019c8e5b08 message_handler + 228
6 libxpc.dylib 0x000000019b6ad168 _xpc_connection_call_event_handler + 152
7 libxpc.dylib 0x000000019b6abbb4 _xpc_connection_mach_event + 1380
8 libdispatch.dylib 0x000000019b7b4274 _dispatch_client_callout4 + 20
9 libdispatch.dylib 0x000000019b7d053c _dispatch_mach_msg_invoke + 464
10 libdispatch.dylib 0x000000019b7bb784 _dispatch_lane_serial_drain + 376
11 libdispatch.dylib 0x000000019b7d125c _dispatch_mach_invoke + 456
12 libdispatch.dylib 0x000000019b7bb784 _dispatch_lane_serial_drain + 376
13 libdispatch.dylib 0x000000019b7bc438 _dispatch_lane_invoke + 444
14 libdispatch.dylib 0x000000019b7c6c98 _dispatch_workloop_worker_thread + 648
15 libsystem_pthread.dylib 0x000000019b974360 _pthread_wqthread + 288
16 libsystem_pthread.dylib 0x000000019b973080 start_wqthread + 8
)
```
### Environment
Version information
```
Visual Studio Community 2022 for Mac
Version 17.5.4 (build 8)
Runtime
.NET 7.0.1 (64-bit)
Architecture: Arm64
Microsoft.macOS.Sdk 12.3.2372; git-rev-head:754abbf6a3563f6267e5717ae832b4ac25b1f2fb; git-branch:release/7.0.1xx-xcode13.3
Roslyn (Language Service)
4.5.0-3.23056.2+97881342e427ff5cdcba8f12b12ff8e6f3564431
NuGet
Version: 6.4.0.117
.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/7.0.203/Sdks
SDK Versions:
7.0.203
6.0.408
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks
.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
7.0.5
6.0.16
Xamarin.Profiler
Version: 1.8.0.49
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
Updater
Version: 11
Apple Developer Tools
Xcode: 14.2 21534
Build: 14C18
Xamarin.Mac
Version: 9.1.1.228 Visual Studio Community
Hash: aacedd12c
Branch: main
Build date: 2023-03-14 19:59:39-0400
Xamarin.iOS
Version: 16.4.0.6 Visual Studio Community
Hash: 97731c92c
Branch: xcode14.3
Build date: 2023-04-11 22:38:36-0400
Xamarin Designer
Version: 17.5.3.47
Hash: e8b5d371c3
Branch: remotes/origin/d17-5
Build date: 2023-04-05 15:58:40 UTC
Xamarin.Android
Not Installed
Microsoft Build of OpenJDK
Java SDK: Not Found
Eclipse Temurin JDK
Java SDK: Not Found
Android SDK Manager
Version: 17.5.0.33
Hash: f0c0c52
Branch: remotes/origin/d17-5~2
Build date: 2023-04-05 15:58:45 UTC
Android Device Manager
Version: 0.0.0.1245
Hash: 7f8a990
Branch: 7f8a990
Build date: 2023-04-05 15:58:45 UTC
Build Information
Release ID: 1705040008
Git revision: 9a2f0e1a7e2107e6b1174c241a1ca232cde57c49
Build date: 2023-04-05 15:56:57+00
Build branch: release-17.5
Build lane: release-17.5
Operating System
Mac OS X 12.6.5
Darwin 21.6.0 Darwin Kernel Version 21.6.0
Thu Mar 9 20:12:21 PST 2023
root:xnu-8020.240.18.700.8~1/RELEASE_ARM64_T6000 arm64
```
### Example Project
[XpcDotNet.zip](https://github.com/xamarin/xamarin-macios/files/11423624/XpcDotNet.zip)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the attached XpcDotNet.zip sample and its README, including the signing instructions, then run the reproduction on .NET 7 or .NET 8 and inspect the Console output for the NSXPCDecoder exception. Compare the behavior with the .NET Framework 4.7.2 target; done means the XPC service receives the app's Ping call without crashing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, macos
- Domain
- desktop-dev, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100