title: ASP.NET Core "An error occurred while starting the application" after adding UseSession() in config
body: <p>As the title says, right after adding UseSession() to my configuration I get: &quot;<em>An error occurred while starting the application. .NET Core 4.6.28801.04 X64 v4.0.0.0 | Microsoft.AspNetCore.Hosting version 2.2.7-servicing-10089 | Microsoft Windows 10.0.18363 |</em>&quot; when running the app. This is the only message I see.</p>
  <p>If I want the app to start working again, I just comment out the <em>UseSession()</em> call. So that's the best hint I have. Now I do find it strange that I don't have to import (open) the library <em>Microsoft.AspNetCore.Session</em>, but if I remove it from the packages then the <em>UseSession()</em> extension method can't be found.</p>
  <pre><code>open Microsoft.AspNetCore.Session //not needed according to the compiler?
  let configureApp (app : IApplicationBuilder) =
        app
          .UseCors(configureCors)
          .UseStaticFiles()
          .UseAuthentication()
          .UseSession() // &lt;------- crashes the startup
          .UseGiraffe(webApp)
  </code></pre>
  <p>I separated those chained calls into individual ones and see if the application would throw at the UseSession() line, but it doesn't. It crashes in the main <em>WebHostBuilder.Build().Run()</em> method.</p>
  <p>I've read the <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-2.1#session-state-1" rel="nofollow noreferrer">docs</a> on how to add the session, I've payed attention to <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-2.1#order" rel="nofollow noreferrer">the order of the middleware</a>, I've cleaned the project, updated all dependencies, restarted visual studio (2019 Pro if it matters), restarted the computer, removed and reinstalled the Microsoft.AspNetCore.Session nuget package.</p>
  <p>I'm targeting .NET core 2.1 (even though I'm compiling with the 3.1 SDK). The application is written in F# and I'm using Giraffe as my web framework (which sits on top of ASP.NET core).</p>
  <p>Any ideas on how to solve this? Or the direction I should take to diagnose better?
  My only hunch is that the nuget packages are not playing nicely together.</p>
  <p>These are the dependencies on the web project:</p>
  <pre><code>FSharp.Data
  Microsoft.AspNetCore.Cors
  Microsoft.AspNetCore.Hosting
  Microsoft.AspNetCore.Diagnostics
  Microsoft.AspNetCore.Server.Kestrel
  Microsoft.AspNetCore.Server.IISIntegration
  Microsoft.AspNetCore.StaticFiles
  Microsoft.AspNetCore.Authentication.Cookies
  Microsoft.AspNetCore.Authentication.JwtBearer
  Microsoft.AspNetCore.Session
  Microsoft.Extensions.Logging.Console
  Microsoft.Extensions.Logging.Debug
  Microsoft.Extensions.DependencyInjection
  Microsoft.Extensions.Configuration.Json
  Microsoft.FSharpLu.Json
  Giraffe
  Giraffe.SerilogExtensions
  Serilog.Sinks.RollingFile
  </code></pre>
  <p>Thanks so much for putting some of your time into this.</p>