Xamarin Hot Reload 没有初始化失败

Posted

技术标签:

【中文标题】Xamarin Hot Reload 没有初始化失败【英文标题】:Xamarin Hot Reload not failed to initialize 【发布时间】:2021-07-09 08:55:45 【问题描述】:

在 Visual Studio 版本 16.9.x 的最后一次更新和更新到 Xamarin.Forms 5.0 热重载后无法正常工作。

这是我启动应用程序时得到的输出:

Hot Reload IDE Extension Loaded
(FinansovoPregledi.android) XAML Hot Reload is using 'changes only' mode
XAML Hot Reload initializing...
WARN: (FinansovoPregledi.Android) Unknown Breakpoint Hit: Android.Runtime.JNIEnv.RegisterJniNatives( typeName_ptr, int typeName_len,  jniClass,  methods_ptr, int methods_len)
ERROR: Caught exception in AgentStatusChangedHandler at 268: Xamarin.HotReload.EvaluatorException: Failed to Inject Assembly ---> Mono.Debugging.Evaluation.EvaluatorException: Method `Load' not found in type `System.Reflection.Assembly'.
   at Mono.Debugging.Soft.SoftDebuggerAdaptor.OverloadResolveMulti(SoftEvaluationContext ctx, TypeMirror type, String methodName, ArgumentType[] genericTypeArgs, TypeMirror returnType, ArgumentType[] argTypes, List`1 candidates, Boolean throwIfNotFound, Boolean tryCasting) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2619
   at Mono.Debugging.Soft.SoftDebuggerAdaptor.OverloadResolveMulti(SoftEvaluationContext ctx, TypeMirror type, String methodName, ArgumentType[] genericTypeArgs, TypeMirror returnType, ArgumentType[] argTypes, Boolean allowInstance, Boolean allowStatic, Boolean throwIfNotFound, Boolean tryCasting) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2511
   at Mono.Debugging.Soft.SoftDebuggerAdaptor.RuntimeInvoke(EvaluationContext ctx, Object targetType, Object target, String methodName, Object[] genericTypeArgs, Object[] argTypes, Object[] argValues, Boolean enableOutArgs, Object[]& outArgs) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2304
   at Mono.Debugging.Soft.SoftDebuggerAdaptor.RuntimeInvoke(EvaluationContext ctx, Object targetType, Object target, String methodName, Object[] genericTypeArgs, Object[] argTypes, Object[] argValues) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2281
   at Xamarin.HotReload.HotReloadSharedBridge.InjectAndLoadAssembly(IProject project, SoftEvaluationContext context, String assemblyPath) in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadSharedBridge.cs:line 359
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
   --- End of inner exception stack trace ---
   at Xamarin.HotReload.HotReloadSharedBridge.InjectAndLoadAssembly(IProject project, SoftEvaluationContext context, String assemblyPath) in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadSharedBridge.cs:line 374
   at Xamarin.HotReload.HotReloadBridge.<InitializeAgent>d__47.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 140
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.HotReload.HotReloadBridge.<<Debugger_TargetHitBreakpoint>b__50_0>d.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 242
   at Xamarin.HotReload.HotReloadSharedBridge.InjectAndLoadAssembly(IProject project, SoftEvaluationContext context, String assemblyPath) in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadSharedBridge.cs:line 374
   at Xamarin.HotReload.HotReloadBridge.<InitializeAgent>d__47.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 140
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.HotReload.HotReloadBridge.<<Debugger_TargetHitBreakpoint>b__50_0>d.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 242
XAML Hot Reload encountered a problem and failed to start. Use Help -> Report a Problem if the issues persists.
Stopping All Hot Reload sessions due to Failed ...
(FinansovoPregledi.Android) Stopping a Hot Reload session due to Failed ...
Stopped Hot Reload session.
ERROR: (FinansovoPregledi.Android) Caught exception in Debugger_TargetHitBreakpoint at 246: Xamarin.HotReload.EvaluatorException: Failed to Inject Assembly ---> Mono.Debugging.Evaluation.EvaluatorException: Method `Load' not found in type `System.Reflection.Assembly'.
   at Mono.Debugging.Soft.SoftDebuggerAdaptor.OverloadResolveMulti(SoftEvaluationContext ctx, TypeMirror type, String methodName, ArgumentType[] genericTypeArgs, TypeMirror returnType, ArgumentType[] argTypes, List`1 candidates, Boolean throwIfNotFound, Boolean tryCasting) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2619
   at Mono.Debugging.Soft.SoftDebuggerAdaptor.OverloadResolveMulti(SoftEvaluationContext ctx, TypeMirror type, String methodName, ArgumentType[] genericTypeArgs, TypeMirror returnType, ArgumentType[] argTypes, Boolean allowInstance, Boolean allowStatic, Boolean throwIfNotFound, Boolean tryCasting) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2511
   at Mono.Debugging.Soft.SoftDebuggerAdaptor.RuntimeInvoke(EvaluationContext ctx, Object targetType, Object target, String methodName, Object[] genericTypeArgs, Object[] argTypes, Object[] argValues, Boolean enableOutArgs, Object[]& outArgs) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2304
   at Mono.Debugging.Soft.SoftDebuggerAdaptor.RuntimeInvoke(EvaluationContext ctx, Object targetType, Object target, String methodName, Object[] genericTypeArgs, Object[] argTypes, Object[] argValues) in C:\A\1\216\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerAdaptor.cs:line 2281
   at Xamarin.HotReload.HotReloadSharedBridge.InjectAndLoadAssembly(IProject project, SoftEvaluationContext context, String assemblyPath) in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadSharedBridge.cs:line 359
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
   --- End of inner exception stack trace ---
   at Xamarin.HotReload.HotReloadSharedBridge.InjectAndLoadAssembly(IProject project, SoftEvaluationContext context, String assemblyPath) in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadSharedBridge.cs:line 374
   at Xamarin.HotReload.HotReloadBridge.<InitializeAgent>d__47.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 140
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.HotReload.HotReloadBridge.<<Debugger_TargetHitBreakpoint>b__50_0>d.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 242
   at Xamarin.HotReload.HotReloadSharedBridge.InjectAndLoadAssembly(IProject project, SoftEvaluationContext context, String assemblyPath) in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadSharedBridge.cs:line 374
   at Xamarin.HotReload.HotReloadBridge.<InitializeAgent>d__47.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 140
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Xamarin.HotReload.HotReloadBridge.<<Debugger_TargetHitBreakpoint>b__50_0>d.MoveNext() in D:\a\1\s\HotReload\Source\Xamarin.HotReload.Bridge\HotReloadBridge.cs:line 242

有人有同样的问题吗?我尝试了所有平台的一切,还选择刷新整个页面,但没有解决我的问题。没有 Hot Reload 太难了。

【问题讨论】:

自 16.9.3 起,我不得不更改我的设置工具 -> 选项 -> 调试 -> 热重载并将模式从仅更改设置为完整页面以使其再次工作。 @GertjanBrouwer 我试过不行 @Rajzer 在您的 Android 和 ios 构建设置中,检查链接器是否设置为“不链接”或“无链接”。 @CherryBu-MSFT 标记为答案 @Rajzer 很高兴为您提供帮助,我现在已经为您的帖子回复了一条。 【参考方案1】:

在您的 Android 和 iOS 构建设置中,检查链接器是否设置为“不链接”或“无链接”。 更多关于 Xamarin.Forms 的 XAML Hot Reload 的详细信息,你可以看看:

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/hot-reload

【讨论】:

他们没有链接设置!措辞已经改变,我希望 msfs 会更新他们的 fricking 文档

以上是关于Xamarin Hot Reload 没有初始化失败的主要内容,如果未能解决你的问题,请参考以下文章

Flutter Hot Reload 到多个设备

如何在 Hot Reload 上使用 Provider 维护 Flutter Global BloC 状态?

Android 的 Instant Run vs Flutter Hot Reload 和 React Native Hot Reload 的区别?

Android Studio Flutter Hot Reload热加载无效

关于AndroidStudio的 Hot reload on save not working问题

Xamarin.Forms 热重载在 UWP 中不起作用