500 page is returned where a 404 page should be returned

Hi, I’ve set up my custom error pages as such in my web config files:

	<httpErrors errorMode="Custom" existingResponse="Replace" xdt:Transform="InsertIfMissing">
		<remove statusCode="404" subStatusCode="-1" xdt:Transform="InsertIfMissing"/>
		<remove statusCode="500" subStatusCode="-1" xdt:Transform="InsertIfMissing"/>

		<error statusCode="404" prefixLanguageFilePath="" path="/1227" responseMode="ExecuteURL" xdt:Transform="InsertIfMissing" />
		<error statusCode="500" prefixLanguageFilePath="" path="/1230" responseMode="ExecuteURL" xdt:Transform="InsertIfMissing" />
	</httpErrors>

However a 500 page is returned in every case, even where a 404 page should be returned. Both of the ID’s in the path=“” are ID’s of my 404 and 500 pages respectively, in the backoffice.

In the log viewer I get this error:

System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Umbraco.Core.Configuration.UmbracoSettings.ContentErrorsElement.get_Error404Collection() in D:\a\1\s\src\Umbraco.Core\Configuration\UmbracoSettings\ContentErrorsElement.cs:line 13
   at Umbraco.Core.Configuration.UmbracoSettings.ContentElement.get_Error404Collection() in D:\a\1\s\src\Umbraco.Core\Configuration\UmbracoSettings\ContentElement.cs:line 17
   at Umbraco.Web.Routing.ContentFinderByConfigured404.TryFindContent(PublishedRequest frequest) in D:\a\1\s\src\Umbraco.Web\Routing\ContentFinderByConfigured404.cs:line 57
   at Umbraco.Web.Routing.PublishedRouter.HandlePublishedContent(PublishedRequest request) in D:\a\1\s\src\Umbraco.Web\Routing\PublishedRouter.cs:line 459
   at Umbraco.Web.Routing.PublishedRouter.FindPublishedContentAndTemplate(PublishedRequest request) in D:\a\1\s\src\Umbraco.Web\Routing\PublishedRouter.cs:line 398
   at Umbraco.Web.Routing.PublishedRouter.PrepareRequest(PublishedRequest request) in D:\a\1\s\src\Umbraco.Web\Routing\PublishedRouter.cs:line 131
   at Umbraco.Web.UmbracoInjectedModule.ProcessRequest(HttpContextBase httpContext) in D:\a\1\s\src\Umbraco.Web\UmbracoInjectedModule.cs:line 134
   at Umbraco.Web.UmbracoInjectedModule.<Init>b__18_4(Object sender, EventArgs e) in D:\a\1\s\src\Umbraco.Web\UmbracoInjectedModule.cs:line 414
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Any advice how to move forward?


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/107324-500-page-is-returned-where-a-404-page-should-be-returned