Xamarin 热重启 - 如果使用生成的 class 中的静态 属性(使用文本模板),应用程序会崩溃

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

我正在使用热重启直接调试我的 IPhone。该应用程序仅在使用云解决方案的模拟器中使用热重启时崩溃,该应用程序工作正常。

我有一个 .Resx 文件 AppResources,我正在使用 Xamarin Community Toolkit 提供的翻译扩展,以便能够使用我的 .Resx 中的键我使用文本模板生成键名,以便能够像这样称呼他们:

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

我尝试使用的应用程序崩溃了

Static t4:AppResources.Key

我不知道我做错了什么。我上传了解决方案 GitHub : GitHub Link

是否有解决问题的方法,或者是否有其他方法可以从 .Resx 文件中获取密钥。

感谢您的帮助

这是崩溃报告。

======================================= 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 ..@.H.....@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 ......@...@..i@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.

静态 iOS 库和框架不受支持,如果您的应用程序尝试加载它们,您可能会看到运行时错误或崩溃。使用 HOTRESTART 预处理器符号来阻止执行此代码。支持动态 iOS 库。详情请参考(https:/ /docs.microsoft.com/en-us/xamarin/xamarin-forms/deploy-test/hot-restart)

我通过更改生成密钥的方式解决了这个问题。

更改自

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

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

应用停止崩溃