W10M 上 supsending/resuming 时的异常 - 值不在预期范围内
Exception when supsending/resuming on W10M - Value does not fall within the expected range
我正在使用模板 10 NuGet 版本 1.1.4,当我在我的 Windows 10 移动设备上执行以下操作时看到以下异常:
- 运行 应用程序
- 按 Windows 主页按钮(返回
开始屏幕)
- 运行 再次应用程序
发生的情况是应用程序无法启动,例外情况是:
Value does not fall within the expected range.
调用堆栈:
at Windows.UI.Xaml.Controls.ContentControl.put_Content(Object value)
at Template10.Common.BootStrapper.NavigationServiceFactory(BackButton backButton, ExistingContent existingContent, Frame frame)
at Template10.Common.BootStrapper.NavigationServiceFactory(BackButton backButton, ExistingContent existingContent)
at MyApp.App.OnInitializeAsync(IActivatedEventArgs args)
at Template10.Common.BootStrapper.<InitializeFrameAsync>d__77.MoveNext()
--- 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 Template10.Common.BootStrapper.<InternalLaunchAsync>d__53.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
如果我在 Visual Studio 中处于调试模式并使用生活方式事件 Suspend/Resume,则不会发生这种情况。
我不确定如何进一步调查?有什么想法吗?
谢谢。
编辑: 我的 OnInitializeAsync
函数如下所示:
public override Task OnInitializeAsync(IActivatedEventArgs args)
{
if ((Window.Current.Content as ModalDialog) == null)
{ // setup hamburger shell
var nav = NavigationServiceFactory(BackButton.Attach, ExistingContent.Include);
nav.Frame.ContentTransitions.Clear();//disable animations
Window.Current.Content = new ModalDialog
{ DisableBackButtonWhenModal = true, Content = new Views.LoginPage(), ModalContent = new Views.Busy(), };
}
return Task.CompletedTask;
}
我唯一改变的是 Content = new Views.LoginPage()
而不是 Content = new Views.Shell(nav)
我也遇到过这个问题。问题是您使用重复值多次设置 Window.Current.Content
。您的应用程序中必须有一段代码也设置了内容,或者 OnInitializedAsync
中的空检查不起作用。
如果您不知道这怎么可能,请在 OnInitializedAsync
方法中设置一个断点并检查 null 检查是否有效。另外,请注意 Visual Studio Lifecycle Events 中的 resume 选项可能存在错误或其他问题。它的行为与您实际恢复应用程序时的行为不同。要在附加调试器的情况下测试恢复,只需在调试模式下启动您的应用程序,然后使用生命周期事件按钮暂停它,然后从模拟器的开始屏幕启动它(不要使用 Visual Studio 中的恢复按钮)。
我正在使用模板 10 NuGet 版本 1.1.4,当我在我的 Windows 10 移动设备上执行以下操作时看到以下异常:
- 运行 应用程序
- 按 Windows 主页按钮(返回 开始屏幕)
- 运行 再次应用程序
发生的情况是应用程序无法启动,例外情况是:
Value does not fall within the expected range.
调用堆栈:
at Windows.UI.Xaml.Controls.ContentControl.put_Content(Object value)
at Template10.Common.BootStrapper.NavigationServiceFactory(BackButton backButton, ExistingContent existingContent, Frame frame)
at Template10.Common.BootStrapper.NavigationServiceFactory(BackButton backButton, ExistingContent existingContent)
at MyApp.App.OnInitializeAsync(IActivatedEventArgs args)
at Template10.Common.BootStrapper.<InitializeFrameAsync>d__77.MoveNext()
--- 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 Template10.Common.BootStrapper.<InternalLaunchAsync>d__53.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
如果我在 Visual Studio 中处于调试模式并使用生活方式事件 Suspend/Resume,则不会发生这种情况。
我不确定如何进一步调查?有什么想法吗?
谢谢。
编辑: 我的 OnInitializeAsync
函数如下所示:
public override Task OnInitializeAsync(IActivatedEventArgs args)
{
if ((Window.Current.Content as ModalDialog) == null)
{ // setup hamburger shell
var nav = NavigationServiceFactory(BackButton.Attach, ExistingContent.Include);
nav.Frame.ContentTransitions.Clear();//disable animations
Window.Current.Content = new ModalDialog
{ DisableBackButtonWhenModal = true, Content = new Views.LoginPage(), ModalContent = new Views.Busy(), };
}
return Task.CompletedTask;
}
我唯一改变的是 Content = new Views.LoginPage()
而不是 Content = new Views.Shell(nav)
我也遇到过这个问题。问题是您使用重复值多次设置 Window.Current.Content
。您的应用程序中必须有一段代码也设置了内容,或者 OnInitializedAsync
中的空检查不起作用。
如果您不知道这怎么可能,请在 OnInitializedAsync
方法中设置一个断点并检查 null 检查是否有效。另外,请注意 Visual Studio Lifecycle Events 中的 resume 选项可能存在错误或其他问题。它的行为与您实际恢复应用程序时的行为不同。要在附加调试器的情况下测试恢复,只需在调试模式下启动您的应用程序,然后使用生命周期事件按钮暂停它,然后从模拟器的开始屏幕启动它(不要使用 Visual Studio 中的恢复按钮)。