title: UseStatusCodePagesWithReExecute Unhandled Exception Duplicate Key: System.Object
body: <p>AsP.Net Core <code>UseStatusCodePagesWithReExecute()</code>, I'm redirecting to <code>/StatusCode/{0}</code>. I was previously using <code>UseStatusCodePagesWithRedirect()</code> without any apparant issues but since changing, requests that previously redirected now result in an unhandled exception:</p>
  
  <blockquote>
    <p>ArgumentException: An item with the same key has already been added. Key: System.Object</p>
  </blockquote>
  
  <p>Here's the output from the VS15 debug window:</p>
  
  <pre><code>Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:5000/guides/some-guide/introdu  
  Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executing action method WebSite.Controllers.GuideController.ReadSection (WebSite) with arguments (some-guide, introdu) - ModelState is Valid
  Microsoft.EntityFrameworkCore.Storage.IRelationalCommandBuilderFactory:Information: Executed DbCommand (0ms) [Parameters=[@__permalink_0='?' (Size = 450)], CommandType='Text', CommandTimeout='30']
  SELECT TOP(2) [s].[SectionId], [s].[Description], [s].[DisplayPosition], [s].[DocumentId], [s].[Permalink], [s].[Title], [d].[DocumentId], [d].[CategoryId], [d].[Description], [d].[DisplayPosition], [d].[Permalink], [d].[Subtitle], [d].[Title]
  FROM [Sections] AS [s]
  INNER JOIN [Documents] AS [d] ON [s].[DocumentId] = [d].[DocumentId]
  WHERE [s].[Permalink] = @__permalink_0
  ORDER BY [s].[SectionId]
  Microsoft.AspNetCore.Mvc.StatusCodeResult:Information: Executing HttpStatusCodeResult, setting HTTP status code 404
  Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action WebSite.Controllers.GuideController.ReadSection (WebSite) in 15.6192ms
  Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executing action method WebSite.Controllers.ErrorController.StatusCode (WebSite) with arguments (404) - ModelState is Valid
  WebSite.Controllers.ErrorController:Information: Unexpected Status Code: 404, OriginalPath: /guides/some-guide/introdu
  'dotnet.exe' (CoreCLR: clrhost): Loaded 'g4tz3vmn.35h'. Cannot find or open the PDB file.
  Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor:Information: Executing ViewResult, running view at path /Views/Error/Index.cshtml.
  Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action WebSite.Controllers.ErrorController.StatusCode (WebSite) in 86.9564ms
  'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Users\Me\.nuget\packages\System.Diagnostics.StackTrace\4.3.0\lib\netstandard1.3\System.Diagnostics.StackTrace.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
  'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.1.0\System.IO.MemoryMappedFiles.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
  'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.1.0\System.IO.UnmanagedMemoryStream.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
  Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware:Error: An unhandled exception has occurred while executing the request
  
  System.ArgumentException: An item with the same key has already been added. Key: System.Object
     at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException(Object key)
     at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeNextResourceFilter&gt;d__22.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
     at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&lt;InvokeAsync&gt;d__20.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Builder.RouterMiddleware.&lt;Invoke&gt;d__4.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at WebMarkupMin.AspNetCore1.WebMarkupMinMiddleware.&lt;Invoke&gt;d__5.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.&lt;&gt;c__DisplayClass6_0.&lt;&lt;UseStatusCodePagesWithReExecute&gt;b__0&gt;d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.&lt;Invoke&gt;d__3.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.VisualStudio.Web.BrowserLink.Runtime.BrowserLinkMiddleware.&lt;ExecuteWithFilter&gt;d__7.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.&lt;Invoke&gt;d__7.MoveNext()
  Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 342.116ms 500 text/html; charset=utf-8
  </code></pre>
  
  <p>It looks like it's executing my StatusCode controller action fine, logging the original path of the error and then bam, I get the exception. What is causing this error?</p>