Why are some pages throwing a 500 error that I can't catch?

  • Page Owner: Not Set
  • Last Reviewed: 2020-10-20

I have a bunch of pages that are all throwing 500 errors. These exceptions happened shortly after an Episerver upgrade. The exception isn't getting caught by Visual Studio or Sentry. A breakpoint in the page controller isn't even getting hit. The only unusual thing about this page is it uses a partial router, but the partial router is not throwing any exceptions and appears to be working. What's going on here?


Answer

It's possible that you're setting segmentContext.RemainingPath to null inside your partial router. If so, that is likely the problem. In older versions of Episerver, this didn't seem to cause a problem, but in more recent (as of this writing) versions, it causes an exception inside some Episerver code where it's not possible to catch it. Instead of null, you can assign it an empty string, or the remaining segments.

So change this:

     segmentContext.RemainingPath = null;

To this:

     segmentContext.RemainingPath = segmentContext.GetNextValue(segmentContext.RemainingPath).Remaining;