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

Invoking async swift code in an iOS binding library is returning an objective C encoding error #16199

Closed
jerrgreen opened this issue Jul 17, 2023 · 1 comment
Labels
external partner/macios Issues for the Mac / iOS SDK platform/iOS 🍎 t/bug Something isn't working

Comments

@jerrgreen
Copy link

Description

I am trying to integrate an iOS binding library with a swift library that uses asynchronous methods. When I hit a method that is synchronous, the method executes successfully. When I try to invoke any asynchronous method, the app crashes. The last exception that I see in the logs is "Microsoft.iOS: Unsupported type encoding: "NSString"16@?<v@?@"NSString">24".

Referencing the Binding details for Xamarin,, I'd expect this to be fully supported, but I cannot find a way past this error.

I've been able to reproduce this on both the latest versions of dotnet 6 and dotnet 7.

Steps to Reproduce

  1. Have a swift library that utilizes async code
  2. Create a binding library to that swift library
  3. Attempt to invoke the code from your app - it will crash

Sample from the ApiDefinition:

        // @interface TestClass : NSObject
	[BaseType (typeof(NSObject))]
	interface TestClass
	{
		// -(NSString * _Nonnull)DebugLogWithMessage:(NSString * _Nonnull)message __attribute__((warn_unused_result("")));
		[Export ("DebugLogWithMessage:")]
		string DebugLogWithMessage (string message);

		// -(void)DebugLog2WithMessage:(NSString * _Nonnull)message completionHandler:(void (^ _Nonnull)(NSString * _Nonnull))completionHandler;
		[Export ("DebugLog2WithMessage:completionHandler:"), Async]
		void DebugLog2WithMessage (string message, Action<NSString> completionHandler);
	}

Sample from the application:

        public partial async Task<string> DebugLog(string message)
        {
            var testClass = new TestClass();

            // This works
            Console.WriteLine("Printing first message");
            Console.WriteLine($"ECHO: {testClass.DebugLogWithMessage(message)}");

            // This does not (Microsoft.iOS: Unsupported type encoding: "NSString"16@?<v@?@"NSString">24)
            Console.WriteLine("Printing second message");
            Console.WriteLine($"ECHO: {await testClass.DebugLog2WithMessageAsync(message)}");

            return "";
        }

Link to public reproduction project repository

https://github.com/jerrgreen/MauiIosAsync

Version with bug

7.0.86

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 16.2

Did you find any workaround?

No

Relevant log output

2023-07-17 11:59:48.048 MauiAppForAsync[758:186937] Printing first message

2023-07-17 11:59:48.051 MauiAppForAsync[758:186937] ECHO: test

2023-07-17 11:59:48.051 MauiAppForAsync[758:186937] Printing second message

2023-07-17 11:59:48.053 MauiAppForAsync[758:186937] Microsoft.iOS: Unsupported type encoding: "NSString"16@?<v@?@"NSString">24

test




=================================================================

Native Crash Reporting

=================================================================

Got a SIGABRT while executing native code. This usually indicates

a fatal error in the mono runtime or one of the native libraries

used by your application.

=================================================================




=================================================================

Native stacktrace:

=================================================================

0x1010a4b18 - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode

0x10108fc14 - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode

0x1011d7818 - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode

0x1010a432c - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode

0x219314a90 - /usr/lib/system/libsystem_platform.dylib : <redacted>

0x2193b01ac - /usr/lib/system/libsystem_pthread.dylib : pthread_kill

0x1d2998c8c - /usr/lib/system/libsystem_c.dylib : abort

0x100dae458 - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : xamarin_get_block_descriptor

0x100db2ed8 - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : xamarin_find_protocol_wrapper_type

0x100db7228 - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _Z9__isctypeim

0x100dc6060 - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _ZN16XamarinCallState3selEv

0x100d8142c - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync :

0x1010b2de8 - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode

0x1010a856c - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode

0x1010a6044 - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode

0x10107704c - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode

0x100fc6714 - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode

0x100fdad44 - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode

0x100fdaad4 - /private/var/containers/Bundle/Application/18836C3D-F2F9-401F-82F9-90E023402D25/PublicStaging.app/MauiAppForAsync : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode

0x2193aa6cc - /usr/lib/system/libsystem_pthread.dylib : _pthread_start

0x2193a9ba4 - /usr/lib/system/libsystem_pthread.dylib : thread_start




=================================================================

Basic Fault Address Reporting

=================================================================

Memory around native instruction pointer (0x208c93160):0x208c93150  ff 0f 5f d6 c0 03 5f d6 10 29 80 d2 01 10 00 d4  .._..._..)......

0x208c93160  03 01 00 54 7f 23 03 d5 fd 7b bf a9 fd 03 00 91  ...T.#...{......

0x208c93170  8e ed ff 97 bf 03 00 91 fd 7b c1 a8 ff 0f 5f d6  .........{...._.

0x208c93180  c0 03 5f d6 7f 23 03 d5 fd 7b bf a9 fd 03 00 91  .._..#...{......




=================================================================

Managed Stacktrace:

=================================================================

  at <unknown> <0xffffffff>

  at ApiDefinitions.Messaging:void_objc_msgSend_NativeHandle_NativeHandle <0x0006e>

  at IosBinding.TestClass:DebugLog2WithMessage <0x00104>

  at IosBinding.TestClass:DebugLog2WithMessageAsync <0x00060>

  at <DebugLog>d__0:MoveNext <0x000d0>

  at System.Runtime.CompilerServices.AsyncMethodBuilderCore:Start <0x00076>

  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:Start <0x0000e>

  at MauiAppForAsync.Services.AsyncInvokerService:DebugLog <0x00084>

  at <<OnClicked>b__0>d:MoveNext <0x0005a>

  at System.Runtime.CompilerServices.AsyncMethodBuilderCore:Start <0x00076>

  at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:Start <0x0000e>

  at <>c__DisplayClass1_0:<OnClicked>b__0 <0x00070>

  at System.Threading.Tasks.Task`1:InnerInvoke <0x0004a>

  at <>c:<.cctor>b__273_0 <0x0001c>

  at System.Threading.ExecutionContext:RunFromThreadPoolDispatchLoop <0x00064>

  at System.Threading.Tasks.Task:ExecuteWithThreadLocal <0x001ee>

  at System.Threading.Tasks.Task:ExecuteEntryUnsafe <0x00082>

  at System.Threading.Tasks.Task:ExecuteFromThreadPool <0x00014>

  at System.Threading.ThreadPoolWorkQueue:DispatchWorkItem <0x00042>

  at System.Threading.ThreadPoolWorkQueue:DispatchItemWithAutoreleasePool <0x00054>

  at System.Threading.ThreadPoolWorkQueue:Dispatch <0x00382>

  at WorkerThread:WorkerThreadStart <0x00108>

  at StartHelper:RunWorker <0x00086>

  at StartHelper:Run <0x0006a>

  at System.Threading.Thread:StartCallback <0x00040>

  at System.Object:runtime_invoke_direct_void__this__ <0x00048>

  at <unknown> <0x00000>
@jerrgreen jerrgreen added the t/bug Something isn't working label Jul 17, 2023
@drasticactions
Copy link
Contributor

@jerrgreen I can't transfer issues from one org to another, but I think this issue should go to xamarin-macios, it's specific to the iOS SDK and not something that can be fixed in this repo.

If you try running your framework inside a net7.0-ios app, without invoking the MAUI UI Framework (Which is what this repo is for) you can get the same exception. This is an SDK question or issue that cannot be addressed here. But hopefully, we can figure it out over in that repo.

CC @rolfbjarne.

@drasticactions drasticactions closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2023
@samhouts samhouts added partner/macios Issues for the Mac / iOS SDK external labels Jul 25, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
external partner/macios Issues for the Mac / iOS SDK platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants