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