在W10M上进行暂停/恢复时发生异常-值不在预期范围内 [英] Exception when supsending/resuming on W10M - Value does not fall within the expected range

查看:125
本文介绍了在W10M上进行暂停/恢复时发生异常-值不在预期范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用模板10 NuGet版本1.1.4,并且在Windows 10移动设备上执行以下操作时看到以下异常:

I am using Template 10 NuGet Version 1.1.4 and am seeing the following exception when I perform the below actions on my Windows 10 Mobile device:

  1. 运行应用
  2. 按Windows主页按钮(将我带回到 开始屏幕)
  3. 再次运行应用程序
  1. Run the App
  2. Press the Windows Home button (takes me back to the Start screen)
  3. Run the App again

发生的情况是该应用程序无法启动,但以下情况除外:

What happens is that the app fails to start, with an exception of:

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中处于调试模式,并且使用生活方式事件来挂起/恢复,则不会发生这种情况.

This doesn't happen if I am in debug mode in Visual Studio and use the lifestyle events to Suspend/Resume.

我不确定该如何进一步调查?有什么想法吗?

I am not sure how to investigate this further? Any ideas?

谢谢.

我的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)

The only thing that I have changed is Content = new Views.LoginPage() instead of Content = new Views.Shell(nav)

推荐答案

我也遇到了这个问题.问题是您要使用重复的值多次设置Window.Current.Content.您的应用中必须有一段代码可以设置内容,否则OnInitializedAsync中的null检查无效.

I have also faced this issue. The problem is that you are setting the Window.Current.Content multiple times using a duplicate value. There has to be a piece of code somewhere in your app which also sets the content OR the null check in OnInitializedAsync does not work.

如果您不知道怎么可能,请在OnInitializedAsync方法中设置一个断点,然后检查null检查是否有效.另外,请注意,Visual Studio生命周期事件中的恢复"选项可能已出现错误或其他错误.它的行为与您实际恢复应用程序的行为不同.要在连接了调试器的情况下测试恢复,只需在调试模式下启动您的应用程序,然后使用生命周期事件"按钮将其挂起,然后从仿真器的开始"屏幕(不使用Visual Studio中的恢复"按钮)启动它即可.

If you have no idea how is that possible, set up a break point in the OnInitializedAsync method and check whether the null check works. Also, beware that the resume option in Visual Studio Lifecycle Events is probably bugged or something. It has a different behavior than if you actually resume your app. To test the resuming with a debugger attached, simply launch your app in debug mode, then suspend it using the Lifecycle Events button, and then launch it from the emulator's start screen (do NOT use the Resume button in Visual Studio).

这篇关于在W10M上进行暂停/恢复时发生异常-值不在预期范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆