xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.49k stars 515 forks source link

OSLog constructor yields System.TypeInitializationException: handle is null #7959

Closed t9mike closed 4 years ago

t9mike commented 4 years ago

Steps to Reproduce

  1. Create iOS phone project
  2. Add var oslog = new OSLog(NSBundle.MainBundle.BundleIdentifier, "Test"); to controller's ViewDidLoad
  3. Get exception

Expected Behavior

Construct an OSLog

Actual Behavior

System.TypeInitializationException: The type initializer for 'CoreFoundation.OSLog' threw an exception. ---> System.Exception: Could not initialize an instance of the type 'CoreFoundation.OSLog': handle is null. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false. at CoreFoundation.NativeObject.InitializeHandle (System.IntPtr handle) [0x00014] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.30/src/Xamarin.iOS/CoreFoundation/NativeObject.cs:74 at CoreFoundation.NativeObject.set_Handle (System.IntPtr value) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.30/src/Xamarin.iOS/CoreFoundation/NativeObject.cs:34 at CoreFoundation.NativeObject..ctor (System.IntPtr handle, System.Boolean owns) [0x00006] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.30/src/Xamarin.iOS/CoreFoundation/NativeObject.cs:43 at CoreFoundation.OSLog..ctor (System.IntPtr handle, System.Boolean owns) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.30/src/Xamarin.iOS/CoreFoundation/OSLog.cs:59 at CoreFoundation.OSLog..cctor () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.30/src/Xamarin.iOS/CoreFoundation/OSLog.cs:32 --- End of inner exception stack trace --- at OSLogTest.ViewController.ViewDidLoad () [0x00008] in /Users/mmuegel/Projects/OSLogTest/ViewController.cs:19 at at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.30/src/Xamarin.iOS/UIKit/UIApplication.cs:86 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.14.1.30/src/Xamarin.iOS/UIKit/UIApplication.cs:65 at OSLogTest.Application.Main (System.String[] args) [0x00001] in /Users/mmuegel/Projects/OSLogTest/Main.cs:12

Environment

=== Visual Studio Community 2019 for Mac (Preview) ===

Version 8.5 Preview (8.5 build 2987)
Installation UUID: 49afa5cc-00b9-4c18-a240-552efe177384
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 6.14.1.30 (d16-5 / 4cc97e67)

    Package version: 608000106

=== Mono Framework MDK ===

Runtime:
    Mono 6.8.0.106 (2019-10/0e18125d711) (64-bit)
    Package version: 608000106

=== Roslyn (Language Service) ===

3.5.0-beta2-20052-02+04aada103893143c9da8a96bdc465e106c1f0151

=== NuGet ===

Version: 5.4.0.6315

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/3.1.101/Sdks
SDK Versions:
    3.1.101
    3.1.100
    3.0.101
    3.0.100
    2.2.203
    2.1.505
    2.1.504
    2.1.503
    2.1.500
    2.1.302
    2.0.0
    1.0.0-preview2-1-003177
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.8.0/lib/mono/msbuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    3.1.1
    3.1.0
    3.0.1
    3.0.0
    2.2.4
    2.1.15
    2.1.14
    2.1.13
    2.1.9
    2.1.8
    2.1.7
    2.1.6
    2.1.2
    2.0.0
    1.1.0

=== Xamarin.Profiler ===

Version: 1.6.12.26
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 10.2.0.84 (Visual Studio Community)
Commit: xamarin-android/d16-5/ac3f71f
Android SDK: /Users/mmuegel/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.0
SDK Build Tools Version: 27.0.3

Build Information: 
Mono: df42020
Java.Interop: xamarin/java.interop/d16-5@c0cc770
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.28.0@46204c4
Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/mmuegel/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.5.0.38
Hash: 5adcbfa
Branch: remotes/origin/d16-5~1
Build date: 2020-02-13 23:02:30 UTC

=== Android Device Manager ===

Version: 16.5.0.65
Hash: 327dcef
Branch: remotes/origin/d16-5-fix/mac-pre-catalina~1
Build date: 2020-02-13 23:02:52 UTC

=== Xamarin Designer ===

Version: 16.5.0.459
Hash: 8aade6148
Branch: remotes/origin/d16-5
Build date: 2020-02-04 08:22:34 UTC

=== Apple Developer Tools ===

Xcode 11.3.1 (15715)
Build 11C505

=== Xamarin.Mac ===

Version: 6.14.1.30 (Visual Studio Community)
Hash: 4cc97e67
Branch: d16-5
Build date: 2020-02-04 08:39:21-0500

=== Xamarin.iOS ===

Version: 13.14.1.30 (Visual Studio Community)
Hash: 4cc97e67
Branch: d16-5
Build date: 2020-02-04 08:39:21-0500

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 805002987
Git revision: 466e632f6c8e74ecc2efc78bd9ae10c7d3b7ee30
Build date: 2020-02-14 13:34:22-05
Build branch: release-8.5
Xamarin extensions: 466e632f6c8e74ecc2efc78bd9ae10c7d3b7ee30

=== Operating System ===

Mac OS X 10.15.3
Darwin 19.3.0 Darwin Kernel Version 19.3.0
    Thu Jan  9 20:58:23 PST 2020
    root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64

Build Logs

Example Project (If Possible)

OSLogTest.zip #

spouliot commented 4 years ago

https://github.com/xamarin/xamarin-macios/pull/7141

sadly approved without https://github.com/xamarin/xamarin-macios/pull/7141#issuecomment-536878828

spouliot commented 4 years ago

Got an idea for a new introspection tests to run all .cctor :) I'll fix that while testing the test...

t9mike commented 4 years ago

Thank you @spouliot. Is there a nightly build or other installer available to try this out?

spouliot commented 4 years ago

@t9mike soon but not yet. Packages are built after the PR is merged (which happened 2 hours ago). Look at the commit itself, e.g. https://github.com/xamarin/xamarin-macios/commit/9a8855117bb855aaff65b7aaaa67d9fdc8f4e6f6 for master, and (in a few hours) you'll see packages that correspond to the commit.

A bit later (once the back port to d16-6 is merged) you'll have packages for d16-6 (our next public release).

t9mike commented 4 years ago

@spouliot I was able to use OSLog against iPhone real device OK and saw expected output in Console. With watchOS real device, I get crash. But this is unrelated to OSLog as once I disabled OSLog I still get crash. OK on simulator.

I used stock Release channel everything else and installed Xamarin.iOS 13.19.0.76 package. Do I need to install other packages to try this out on watchOS?

0   libsystem_kernel.dylib              0x21050c70 __pthread_kill + 8
1   libsystem_pthread.dylib             0x210cd980 pthread_kill + 220
2   libsystem_c.dylib                   0x20fa46f4 abort + 100
3   SundialWatchAppExtension            0x04cec534 print_callback(char const*, int) + 12584244 (runtime.m:1218)
4   SundialWatchAppExtension            0x04cda330 monoeg_g_logv_nofree + 12510000 (goutput.c:150)
5   SundialWatchAppExtension            0x04cda380 monoeg_g_log + 12510080 (goutput.c:165)
6   SundialWatchAppExtension            0x04ccc9b8 mono_threads_transition_do_blocking + 12454328 (mono-threads-state-machine.c:753)
7   SundialWatchAppExtension            0x04cca4a0 mono_threads_enter_gc_safe_region_unbalanced_with_info + 12444832 (mono-threads-coop.c:324)
8   SundialWatchAppExtension            0x04c36a6c mono_gc_pthread_create + 11840108 (sgen-mono.c:2444)
9   SundialWatchAppExtension            0x04ccb784 mono_thread_platform_create_thread + 12449668 (mono-threads-posix.c:97)
10  SundialWatchAppExtension            0x04c59b08 create_thread + 11983624 (threads.c:1385)
11  SundialWatchAppExtension            0x04c595cc mono_thread_create_internal + 11982284 (threads.c:529)
12  SundialWatchAppExtension            0x04bb3ca0 mono_gc_init_finalizer_thread + 11304096 (gc.c:1004)
13  SundialWatchAppExtension            0x04cf3dd8 -[XamarinGCSupport init] + 12615128 (monotouch-main.m:0)
14  SundialWatchAppExtension            0x04cf41cc xamarin_main + 12616140 (monotouch-main.m:463)
15  SundialWatchAppExtension            0x041019dc xamarin_watchextension_main + 88540 (main.m:65)
16  libdyld.dylib                       0x20ed0a78 start + 4

Watch extension:

image

spouliot commented 4 years ago

@t9mike the stack trace looks related to the GC initialization (on XI side). Can you file a operate issue for this and attach the symbolicated crash report from the device (so we can see what other threads were doing).

The same fix, backported to d16-6, is now available from packages inside https://github.com/xamarin/xamarin-macios/commit/514991e903313f5c195fcc11700a4d1100e9f530#commitcomment-37486792 That's an older mono (and closer to the current on stable - even if the delta is quite large at this time).