StackOverflowException after upgrading from .Net 6 to .Net 8

Abhishek, Burra 30 Reputation points
2024-05-29T09:57:50.6666667+00:00

Hi,

I have upgraded 5 projects in my solution from .Net 6 to .Net 8 using upgrade assistant in Visual Studio.

When I run the solution, StackOverflowException is being thrown and Swagger is not loading. Looks like onchangetokenfired() method is being called many times resulting in infinite loop.

PFA Startup.cs.txt and Program.cs.txt

Please help in fixing this issue.

User's image

User's image

Developer technologies ASP.NET ASP.NET Core
Developer technologies .NET Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-05-30T09:17:30.4366667+00:00

    Hi,

    CreateHostBuilder() pattern is the .net5 way. Since .net6, the default template has cancelled the Startup.cs` file and use `WebApplication.CreateBuilder like following:

    var builder = WebApplication.CreateBuilder(args);
    ...
    builder.Services.Add...
    var app = builder.Build();
    ...
    app.UseAuthorization();
    ...
    app.Run();
    

    It is not hard to migrate from the old pattern to new pattern. I also suggest you read this classic article talking about this https://andrewlock.net/exploring-dotnet-6-part-2-comparing-webapplicationbuilder-to-the-generic-host/

    ****************************************************************************** 

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".  Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.