Search code examples
xamarinxamarin.iosxamarin-community-toolkit

Xamarin Hot Restart - App crashes if Static Property from generated class (using Text Template) is used


I am using Hot restart to debug directly to my IPhone. The App only crashes while using Hot Restart in the Emulator using Cloud Solution the app works just fine.

I Have a .Resx File AppResources and I am using Translate extension provided from Xamarin Community Toolkit, to be able to use the keys from my .Resx I used Text Template that generates the keys with their names to be able to call them like this:

<Label Text="{toolkit:Translate Text={Static t4:AppResources.Key}}" FontSize="Large" HorizontalOptions="CenterAndExpand"/>
<Label Text="{Static t4:AppResources.Key}" FontSize="Large" HorizontalOptions="CenterAndExpand"/>

The app crashes one I try to use

Static t4:AppResources.Key

I have no Idea what I am doing wrong. I uploaded the Solution GitHub : GitHub Link

Is there a fix for the problem, or another way to be able to get the keys from .Resx File.

Thank you for your Help

This is the crash report.

======================================= Native Crash Reporting ======================================= Got a segv 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: =================================================================

0x102370120 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_dump_native_crash_info

0x102366cbc - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_handle_native_crash 0x102373a60 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_sigsegv_signal_handler_debug 0x1d06bc29c - /usr/lib/system/libsystem_platform.dylib : 0x102514ec4 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : interp_exec_method_full

0x102514ec4 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : interp_exec_method_full 0x102514ec4 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : interp_exec_method_full 0x10250feb0 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : interp_runtime_invoke 0x102376d3c - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_jit_runtime_invoke 0x1024252c0 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_runtime_invoke_checked 0x102428728 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_runtime_invoke 0x102508ccc - /pr ivate/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : xamarin_invoke_trampoline 0x10250e0cc - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : xamarin_arch_trampoline 0x10250ec70 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : xamarin_arm64_common_trampoline 0x1874cf7a8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x1874d123c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x1874d7388 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x186b2ac98 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x187093f58 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : _UIScenePerformActionsWithLifecycleActionMask 0x186b2b830 - /System/Library/Pr ivateFrameworks/UIKitCore.framework/UIKitCore : 0x186b2b2f0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x186b2b640 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x186b2ae7c - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x186b333c0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x186fa1970 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x1870acd68 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : _UISceneSettingsDiffActionPerformChangesWithTransitionContext 0x186b330b8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x18695afa0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x186959920 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x18695abc8 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x1874d5528 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x186fcafd0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x1940775d8 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : 0x1940a2d44 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : 0x1940866a4 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : 0x1940a2a0c - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : 0x1846d281c - /usr/lib/system/libdispatch.dylib : 0x1846d630c - /usr/lib/system/libdispatch.dylib : 0x1940cafa0 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : 0x1940cac30 - /System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices : 0x1940cb184 - /System/Library/PrivateFrameworks/F rontBoardServices.framework/FrontBoardServices : 0x184a5f9e8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : 0x184a5f8e4 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : 0x184a5ebe8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : 0x184a58bc8 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : 0x184a58360 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : CFRunLoopRunSpecific 0x19c096734 - /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices : GSEventRunModal 0x1874d3584 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : 0x1874d8df4 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : UIApplicationMain 0x10251c8fc - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : do_icall 0x10251b010 - /private/ var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : do_icall_wrapper 0x102511a8c - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : interp_exec_method_full 0x10250feb0 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : interp_runtime_invoke 0x102376d3c - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_jit_runtime_invoke 0x1024252c0 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_runtime_invoke_checked 0x10242b974 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_runtime_try_invoke_array 0x1023d39c4 - /private/var/containers/ Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : ves_icall_InternalInvoke 0x1023e3b68 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : ves_icall_InternalInvoke_raw 0x10251c8fc - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : do_icall 0x10251b010 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : do_icall_wrapper 0x102511a8c - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : interp_exec_method_full 0x10250feb0 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : interp_runtime_invoke 0x102376d3c - /private/var/containers/Bundle/Application/95CE4E70-9227-4 3D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_jit_runtime_invoke 0x1024252c0 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_runtime_invoke_checked 0x10242a564 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_runtime_exec_main_checked 0x10235b8f4 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : mono_jit_exec 0x10250d984 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : xamarin_main 0x102323c34 - /private/var/containers/Bundle/Application/95CE4E70-9227-43D7-A04D-AD08B0B10CC9/TF4FileIphoneTest.iOS.app/Xamarin.PreBuilt.iOS : main 0x184714cf8 - /usr/lib/system/libdyld.dylib :

=========================================================== ====== Basic Fault Address Reporting ================================================================= Memory around native instruction pointer (0x102517878):0x102517868 20 01 1f d6 18 0b 00 91 48 83 5f f8 08 10 00 b4 .......H...... 0x102517878 08 11 40 b9 48 83 1f b8 08 03 40 79 a9 0f 00 b0 [email protected].....@y.... 0x102517888 29 a1 33 91 28 79 68 f8 00 01 1f d6 48 83 5f f8 ).3.(yh.....H.. 0x102517898 e8 0e 00 b4 08 01 40 f9 08 01 40 f9 08 69 40 39 ......@[email protected]@9

========================================= Managed Stacktrace: ======================================== at <0xffffffff> at UIKit.UIApplication:UIApplicationMain <0x000b8> at UIKit.UIApplication:Main <0x00020> at UIKit.UIApplication:Main <0x00038> at TF4FileIphoneTest.iOS.Application:Main <0x00012> at :runtime_invoke_direct_void_string[] <0x00092> at <0xffffffff> at System.Reflection.RuntimeMethodInfo:InternalInvoke <0x00030> at System.Refle ction.RuntimeMethodInfo:Invoke <0x000fc> at System.Reflection.MethodBase:Invoke <0x0001a> at Xamarin.PreBuilt.iOS.Applications:Main <0x00254> at :runtime_invoke_direct_void_string[] <0x00092>

The app has been terminated.


Solution

  • I solved the problem by changing the way keys were generated.

    Changed it from

        internal static string <#= entry.Name #>
    {
        get { return nameof(<#= entry.Name #>); }
    }
    

    To

    internal static string <#= entry.Name #> = "<#= entry.Name #>";
    

    The app stopped crashing