title: Navigation failed for an unkown reason
body: <p>This is a very unique problem. Hours of googling have yielded no answers. Hopefully someone here can help.</p>
  
  <p>I have a LightSwitch 2013 application that is working very well for an internal ticketing system with inventory / asset management. It uses Windows Authentication (we have over 900 employees who are all end users with the ability to submit a ticket, so Forms Authentication is useless), and has no problem with that. Using code I've picked up from various blogs, it gets the currently logged in username, and displays their name on the Home screen; it also gets the user's permissions, and hides / displays elements of the UI based on those permissions. All of that works great, and has for some time.</p>
  
  <p>Here's where it gets weird - navigating to the application is successful. The Home screen loads with all the expected buttons. I can click on a button to bring up another screen, any other screen, and that works great. When I click the Application Icon in the Navigation menu to go back to Home, it loads the Home screen, and a dialog pops up that says "Navigation failed for an unknown reason" I click Ok, and the dialog comes back. One more OK and it clears, and I can continue to use the application normally.</p>
  
  <p>I've been doing minor bug fixes and I started implementing reporting on another screen, so there haven't been any changes to the Home screen since long before this started. My testing shows that this happens with every screen, even screens I haven't yet added reporting to.</p>
  
  <p>This is the code for my Home screen:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>/// &lt;reference path="~/GeneratedArtifacts/viewModel.js" /&gt;
  
  
  
  myapp.Home.created = function (screen) {
      // Write code here.
      $.getJSON("../Perms/UserPermissions/", function (data) {
          myapp.permissions = data;
      }).then(function () {
  
          if (myapp.permissions["LightSwitchApplication:ViewTechOnlyScreens"]) {
              screen.details.displayName = "RCC Help Desk Ticketing &amp; Inventory System";
              screen.ScreenName = screen.details.displayName;
              screen.findContentItem("ShowBrowseTickets").isVisible = true;
              screen.findContentItem("Inventory").isVisible = true;
              screen.findContentItem("Users").isVisible = true;
              screen.findContentItem("EnterTicket").isVisible = true;
              screen.findContentItem("SubmitTicket").isVisible = false;
              screen.findContentItem("EnterTicket1").isVisible = true;
              screen.findContentItem("SubmitTicket1").isVisible = false;
              screen.findContentItem("ShowBrowseMyTickets").isVisible = false;
              screen.findContentItem("ShowBrowseOpenTickets").isVisible = true;
              screen.findContentItem("ShowBrowseKB").isVisible = true;
          } else {
              screen.details.displayName = "RCC Help Desk Ticketing System";
              screen.ScreenName = screen.details.displayName;
              screen.findContentItem("ShowBrowseTickets").isVisible = false;
              screen.findContentItem("Inventory").isVisible = false;
              screen.findContentItem("Users").isVisible = false;
              screen.findContentItem("EnterTicket").isVisible = false;
              screen.findContentItem("SubmitTicket").isVisible = true;
              screen.findContentItem("EnterTicket1").isVisible = false;
              screen.findContentItem("SubmitTicket1").isVisible = true;
              screen.findContentItem("ShowBrowseMyTickets").isVisible = true;
              screen.findContentItem("ShowBrowseOpenTickets").isVisible = false;
              screen.findContentItem("ShowBrowseKB").isVisible = true;
          }
  
          if (myapp.permissions["LightSwitchApplication:AddDevice"]) {
  
              screen.findContentItem("ShowAddEditDesktop").isVisible = true;
              screen.findContentItem("ShowAddEditLaptop").isVisible = true;
              screen.findContentItem("ShowAddEditPrinter").isVisible = true;
              screen.findContentItem("ShowAddEditTablet").isVisible = true;
          } else {
              screen.findContentItem("ShowAddEditDesktop").isVisible = false;
              screen.findContentItem("ShowAddEditLaptop").isVisible = false;
              screen.findContentItem("ShowAddEditPrinter").isVisible = false;
              screen.findContentItem("ShowAddEditTablet").isVisible = false;
          }
  
          screen.findContentItem("ShowAddEditEndUser").isVisible = myapp.permissions["LightSwitchApplication:AddEndUser"];
  
          screen.findContentItem("ShowAddEditTech").isVisible = myapp.permissions["LightSwitchApplication:AddTech"];
  
          screen.findContentItem("ShowAddEditDepartment").isVisible = myapp.permissions["LightSwitchApplication:AddDepartment"];
  
          screen.findContentItem("ShowAddEditDeptHead").isVisible = myapp.permissions["LightSwitchApplication:AddDeptHead"];
  
          screen.findContentItem("ShowBrowseHelpFiles").isVisible = myapp.permissions["LightSwitchApplication:AddHelpFile"];
  
          screen.findContentItem("ShowAddEditLocation").isVisible = myapp.permissions["LightSwitchApplication:AddLocation"];
  
          screen.findContentItem("ShowAddEditKBItem").isVisible = myapp.permissions["LightSwitchApplication:AddKnowledgeBase"];
  
          screen.findContentItem("ShowAddEditOperatingSystem").isVisible = myapp.permissions["LightSwitchApplication:AddOS"];
  
          screen.findContentItem("SecurityAdministration").isVisible = myapp.permissions["Microsoft.LightSwitch.Security:SecurityAdministration"];
      });
  };
  
  myapp.Home.EnterTicket_execute = function (screen) {
      // Write code here.
      myapp.showAddTicket(null, {
          beforeShown: function (TicketScreen) {
              var newTicket = new myapp.Ticket();
              TicketScreen.Ticket = newTicket;
              msls.promiseOperation(CallGetUserName).then(function PromiseSuccess(PromiseResult) {
                  myapp.activeDataWorkspace.RCCHelpDeskInventoryData.Techs_SingleOrDefault(PromiseResult)
                      .execute()
                      .then(function (result) {
                          newTicket.Tech = result.results[0];
                      });
              });
          }, afterClosed: function (addEditScreen, navigationAction) {
              if (navigationAction === msls.NavigateBackAction.commit) {
                  var newTicket = addEditScreen.Ticket;
                  myapp.showViewTicket(newTicket, "BrowseOpenTickets");
              }
          }
      });
  };
  
  function CallGetUserName(operation) {
      $.ajax({
          type: 'post',
          data: {},
          url: 'GetUserName.ashx',
          success: operation.code(function AjaxSuccess(AjaxResult) {
              operation.complete(AjaxResult);
          })
      });
  };
  
  myapp.Home.SubmitTicket_execute = function (screen) {
      // Write code here.
      myapp.showSubmitTicket(null, {
          beforeShown: function (TicketScreen) {
              var newTicket = new myapp.Ticket();
              TicketScreen.Ticket = newTicket;
              msls.promiseOperation(CallGetUserName).then(function PromiseSuccess(PromiseResult) {
                  myapp.activeDataWorkspace.RCCHelpDeskInventoryData.EndUsers_SingleOrDefault(PromiseResult)
                      .execute()
                      .then(function (result) {
                          newTicket.EndUser = result.results[0];
                      });
              });
          }, afterClosed: function (addEditScreen, navigationAction) {
              if (navigationAction === msls.NavigateBackAction.commit) {
                  myapp.showViewTicket(addEditScreen.Ticket, "BrowseMyTickets");
              }
          }
      });
  };
  
  myapp.Home.ShowAddEditDesktop_Tap_execute = function (screen) {
      // Write code here.
      myapp.showAddEditDesktop(null, {
          beforeShown: function (addEditScreen) {
              addEditScreen.Desktop = new myapp.Desktop();
          },
          afterClosed: function (addEditScreen, navigationAction) {
              if (navigationAction === msls.NavigateBackAction.commit) {
                  myapp.showViewDesktop(addEditScreen.Desktop);
              }
          }
      });
  };
  
  myapp.Home.ShowAddEditLaptop_Tap_execute = function (screen) {
      // Write code here.
      myapp.showAddEditLaptop(null, {
          beforeShown: function (addEditScreen) {
              addEditScreen.Laptop = new myapp.Laptop();
          },
          afterClosed: function (addEditScreen, navigationAction) {
              if (navigationAction === msls.NavigateBackAction.commit) {
                  myapp.showViewLaptop(addEditScreen.Laptop);
              }
          }
      });
  };
  
  myapp.Home.ShowAddEditPrinter_Tap_execute = function (screen) {
      // Write code here.
      myapp.showAddEditPrinter(null, {
          beforeShown: function (addEditScreen) {
              addEditScreen.Printer = new myapp.Printer();
          },
          afterClosed: function (addEditScreen, navigationAction) {
              if (navigationAction === msls.NavigateBackAction.commit) {
                  myapp.showViewPrinter(addEditScreen.Printer);
              }
          }
      });
  };
  myapp.Home.ShowAddEditTablet_Tap_execute = function (screen) {
      // Write code here.
      myapp.showAddEditTablet(null, {
          beforeShown: function (addEditScreen) {
              addEditScreen.Tablet = new myapp.Tablet();
          },
          afterClosed: function (addEditScreen, navigationAction) {
              if (navigationAction === msls.NavigateBackAction.commit) {
                  myapp.showViewTablet(addEditScreen.Tablet);
              }
          }
      });
  };
  myapp.Home.ShowAddEditEndUser_Tap_execute = function (screen) {
      // Write code here.
      myapp.showAddEditEndUser(null, {
          beforeShown: function (addEditScreen) {
              addEditScreen.EndUser = new myapp.EndUser();
          },
          afterClosed: function (addEditScreen, navigationAction) {
              if (navigationAction === msls.NavigateBackAction.commit) {
                  myapp.showViewEndUser(addEditScreen.EndUser);
              }
          }
      });
  };
  myapp.Home.ShowAddEditTech_Tap_execute = function (screen) {
      // Write code here.
      myapp.showAddEditTech(null, {
          beforeShown: function (addEditScreen) {
              addEditScreen.Tech = new myapp.Tech();
          },
          afterClosed: function (addEditScreen, navigationAction) {
              if (navigationAction === msls.NavigateBackAction.commit) {
                  myapp.showViewTech(addEditScreen.Tech);
              }
          }
      });
  };
  myapp.Home.Tickets_postRender = function (element, contentItem) {
      // Write code here.
      msls.promiseOperation(CallGetUserName).then(function PromiseSuccess(PromiseResult) {
          myapp.activeDataWorkspace.RCCHelpDeskInventoryData.EndUsers_SingleOrDefault(PromiseResult)
              .execute()
              .then(function (result) {
                  $(element).closest("[data-role='page']").find(
                      ".msls-title-area").append(
                      "&lt;div style='color:dimgray;font-size:15px;'&gt;Welcome, " + result.results[0].UserFirstName + " " + result.results[0].UserLastName + "&lt;/div&gt;");
              }, function () {
                  myapp.activeDataWorkspace.RCCHelpDeskInventoryData.EndUsers.addNew();
                  myapp.activeDataWorkspace.RCCHelpDeskInventoryData.saveChanges();
              });
      });
  
      msls.promiseOperation(CallGetUserName).then(function PromiseSuccess(PromiseResult) {
          myapp.activeDataWorkspace.RCCHelpDeskInventoryData.Techs_SingleOrDefault(PromiseResult)
              .execute()
              .then(function (result) {
              }, function () {
                  myapp.activeDataWorkspace.RCCHelpDeskInventoryData.Techs.addNew();
                  myapp.activeDataWorkspace.RCCHelpDeskInventoryData.saveChanges();
              });
      });
  };
  
  myapp.Home.ShowAddEditDepartment_Tap_execute = function (screen) {
      // Write code here.
      myapp.showAddEditDepartment(null, {
          beforeShown: function (addEditScreen) {
              addEditScreen.Department = new myapp.Department();
          },
          afterClosed: function (addEditScreen, navigationAction) {
              if (navigationAction === msls.NavigateBackAction.commit) {
                  myapp.showViewDepartment(addEditScreen.Department);
              }
          }
      });
  };
  myapp.Home.ShowAddEditDeptHead_Tap_execute = function (screen) {
      // Write code here.
      myapp.showAddEditDeptHead(null, {
          beforeShown: function (addEditScreen) {
              addEditScreen.DeptHead = new myapp.DeptHead();
          },
          afterClosed: function (addEditScreen, navigationAction) {
              if (navigationAction === msls.NavigateBackAction.commit) {
                  myapp.showViewDeptHead(addEditScreen.DeptHead);
              }
          }
      });
  };
  
  myapp.Home.ShowHelp_Tap_execute = function (screen) {
      // Write code here.
      screen.getHelpFile().then(function (helpfile) {
          myapp.showHelpDialog(helpfile);
      });
  };
  
  myapp.Home.ShowAddEditKBItem_Tap_execute = function (screen) {
      // Write code here.
      myapp.showAddEditKBItem(null, {
          beforeShown: function (addEditScreen) {
              addEditScreen.KnowledgeBase = new myapp.KnowledgeBase();
          },
          afterClosed: function (addEditScreen, navigationAction) {
              if (navigationAction === msls.NavigateBackAction.commit) {
                  myapp.showViewKBItem(addEditScreen.KnowledgeBase);
              }
          }
      });
  };
  myapp.Home.ShowAddEditLocation_Tap_execute = function (screen) {
      // Write code here.
      myapp.showAddEditLocation(null, {
          beforeShown: function (addEditScreen) {
              addEditScreen.Location = new myapp.Location();
          },
          afterClosed: function (addEditScreen, navigationAction) {
              if (navigationAction === msls.NavigateBackAction.commit) {
                  myapp.showViewLocation(addEditScreen.Location);
              }
          }
      });
  };
  myapp.Home.SecurityAdministration_postRender = function (element, contentItem) {
      // Write code here.
      $(element).find("div").wrap("&lt;a href='http://myserver/Tickets/desktopclient' target='_blank'&gt;&lt;/a&gt;");
  };
  myapp.Home.ShowHelpDialog_Tap_execute = function (screen) {
      // Write code here.
      screen.getHelpFile().then(function () {
          myapp.showHelpDialog(screen.HelpFile);
      });
  };</code></pre>
  </div>
  </div>
  </p>
  
  <p>It's a big chunk of code, but most of it is repetitive code to call various screens (there are 53 total in the application).</p>