0

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

  1. 运行应用程序
  2. 按 Windows 主页按钮(带我回到开始屏幕)
  3. 再次运行应用程序

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

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

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

谢谢。

编辑:我的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)

4

1 回答 1

1

我也遇到过这个问题。问题是您Window.Current.Content使用重复值设置了多次。您的应用程序中的某处必须有一段代码也设置了内容,否则 null 签入OnInitializedAsync不起作用。

如果您不知道这怎么可能,请在方法中设置一个断点OnInitializedAsync并检查 null 检查是否有效。另外,请注意 Visual Studio 生命周期事件中的恢复选项可能存在错误或其他问题。它具有与您实际恢复应用程序不同的行为。要使用附加的调试器测试恢复,只需在调试模式下启动您的应用程序,然后使用 Lifecycle Events 按钮暂停它,然后从模拟器的开始屏幕启动它(不要使用 Visual Studio 中的 Resume 按钮)。

于 2016-02-29T09:39:29.037 回答