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
[src] Use Runtime.NSLog
instead of System.Console.WriteLine
#8626
Conversation
inside the product assemblies [1]. The latter brings a lot [2] of the BCL into the application for, eventually, ending up back to `NSLog` anyway Also include a, cecil-based, test to ensure we don't regress. [1] except for Xamarin.Mac.dll since there's a workaround for a Sierra (only) bug [2]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice 👍 what an interesting fix, I'm so used to CWL that I never considered the overhead of it to just circle back into NSLog ♻️
Build failure Test results1 tests failed, 90 tests passed.Failed tests
|
public void NoSystemConsoleReference (string assemblyPath) | ||
{ | ||
if (Path.GetFileName (assemblyPath) == "Xamarin.Mac.dll") | ||
Assert.Ignore ("Xamarin.Mac has a workaround for Sierra bug w/NSLog"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just out of curiosity: where is this workaround?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xamarin-macios/src/ObjCRuntime/Runtime.cs
Line 1560 in 944ec6d
if (PlatformHelper.CheckSystemVersion (10, 12)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit: 66cbc10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever.
that maps to our, already existing, native `xamarin_log` function. This is important because we can call `NSLog` before our runtime is fully initialized and we hit an issue (see below) when using the managed `NSString`. This worked with `Console.WriteLine` because it ended up using a `NSLog` (inside `mscorlib.dll`) without hitting any ObjC code path. * mmptests ``` 20:55:16.3579440 Unhandled Exception: 20:55:16.3579850 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Foundation.NSString' threw an exception. ---> System.ArgumentNullException: Value cannot be null. 20:55:16.3580020 Parameter name: obj 20:55:16.3580150 at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_monitor_enter_v4_internal(object,intptr) 20:55:16.3580260 at ObjCRuntime.Class.GetClassHandle (System.Type type, System.Boolean throw_if_failure, System.Boolean& is_custom_type) [0x0003d] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3580390 at ObjCRuntime.Class.GetClassHandle (System.Type type) [0x00001] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3580510 at ObjCRuntime.Class.GetHandle (System.Type type) [0x00001] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3580630 at Foundation.NSObject.AllocIfNeeded () [0x0001d] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3580750 at Foundation.NSObject..ctor () [0x00008] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3580870 at Foundation.NSString..ctor (System.String str) [0x00000] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3580980 at Foundation.NSString..cctor () [0x0002d] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3581270 --- End of inner exception stack trace --- 20:55:16.3581420 at ObjCRuntime.Runtime.NSLog (System.String format, System.Object[] args) [0x00001] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3581540 at ObjCRuntime.Dlfcn.dlopen (System.String path, System.Int32 mode) [0x00045] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3581670 at ObjCRuntime.Runtime.LookupInternalFunction[T] (System.String name) [0x00040] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3581790 at ObjCRuntime.Runtime.EnsureInitialized () [0x00036] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3581910 at AppKit.NSApplication.Init () [0x00016] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3582020 at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&) 20:55:16.3582150 at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <dd436d8b1aa7421eb3bcf48b995163c4>:0 20:55:16.3582440 --- End of inner exception stack trace --- 20:55:16.3582600 at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <dd436d8b1aa7421eb3bcf48b995163c4>:0 20:55:16.3582720 at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <dd436d8b1aa7421eb3bcf48b995163c4>:0 20:55:16.3582840 at ConsoleXMApp.MainClass.Main (System.String[] args) [0x00044] in <a2dfeee74db243eab27b7674cfa26c43>:0 20:55:16.3582960 [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Foundation.NSString' threw an exception. ---> System.ArgumentNullException: Value cannot be null. 20:55:16.3583080 Parameter name: obj 20:55:16.3583200 at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_monitor_enter_v4_internal(object,intptr) 20:55:16.3583500 at ObjCRuntime.Class.GetClassHandle (System.Type type, System.Boolean throw_if_failure, System.Boolean& is_custom_type) [0x0003d] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3583650 at ObjCRuntime.Class.GetClassHandle (System.Type type) [0x00001] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3583770 at ObjCRuntime.Class.GetHandle (System.Type type) [0x00001] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3583890 at Foundation.NSObject.AllocIfNeeded () [0x0001d] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3584020 at Foundation.NSObject..ctor () [0x00008] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3584140 at Foundation.NSString..ctor (System.String str) [0x00000] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3584260 at Foundation.NSString..cctor () [0x0002d] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3584380 --- End of inner exception stack trace --- 20:55:16.3584500 at ObjCRuntime.Runtime.NSLog (System.String format, System.Object[] args) [0x00001] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3584620 at ObjCRuntime.Dlfcn.dlopen (System.String path, System.Int32 mode) [0x00045] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3584940 at ObjCRuntime.Runtime.LookupInternalFunction[T] (System.String name) [0x00040] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3585100 at ObjCRuntime.Runtime.EnsureInitialized () [0x00036] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3585230 at AppKit.NSApplication.Init () [0x00016] in <fa73a50c75d24e2bba1062a4d389d50f>:0 20:55:16.3585350 at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&) 20:55:16.3585480 at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <dd436d8b1aa7421eb3bcf48b995163c4>:0 20:55:16.3585600 --- End of inner exception stack trace --- 20:55:16.3585720 at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <dd436d8b1aa7421eb3bcf48b995163c4>:0 20:55:16.3585960 at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <dd436d8b1aa7421eb3bcf48b995163c4>:0 20:55:16.3586110 at ConsoleXMApp.MainClass.Main (System.String[] args) [0x00044] in <a2dfeee74db243eab27b7674cfa26c43>:0 ```
Build success |
inside the product assemblies [1]. The latter brings a lot [2] of the BCL
into the application for, eventually, ending up back to
NSLog
anywayAlso include a, cecil-based, test to ensure we don't regress.
[1] except for Xamarin.Mac.dll since there's a workaround for a
Sierra (only) bug
[2] https://gist.github.com/spouliot/c63343c1a76f4e49248be3a2c7aa25ed
/Users/poupou/Desktop/linker.app/
/Users/poupou/Projects/linker/linker/bin/iPhone/Release/linker.app/