Exception when supsending/resuming on W10M - Value does not fall within the expected range

六眼飞鱼酱① 提交于 2019-12-12 02:44:54

问题


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. 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.

Call Stack:

 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()

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?

Thanks.

Edit: My OnInitializeAsync function looks like:

 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;
        }

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


回答1:


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.

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).



来源:https://stackoverflow.com/questions/35628983/exception-when-supsending-resuming-on-w10m-value-does-not-fall-within-the-expe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!