Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlServer Runner - "StackOverflowException Operation Caused a stack overflow" #1808

Open
jbullen94 opened this issue May 17, 2024 · 1 comment

Comments

@jbullen94
Copy link

Describe the bug
When deploying/attempting to deploy a migration to SqlServer and debugging similar to the samples provided in the repository.
When you try to connect and when enumerating the Migrations, anything called by the runner will result in a "StackOverflowException Operation caused a stack overflow."

static void Main(string[] args)
    {
        var connectionString =
            "Data Source=127.0.0.1;Database=TestDatabase;Integrated Security=false;User ID=sa;Password=yourStrong(!)Password;";
        
        using var services = CreateServices(connectionString);
        using var scope = services.CreateScope();

        var runner = services.GetRequiredService<IMigrationRunner>();

        if (runner.HasMigrationsToApplyUp())
        {
            runner.MigrateUp();
        }
    }

    static ServiceProvider CreateServices(string connectionString)
    {
        return new ServiceCollection()
            // Add common FluentMigrator services
            .AddFluentMigratorCore()
            .ConfigureRunner(rb => rb
                .AddSqlServer()
                // Set the connection string
                .WithGlobalConnectionString(connectionString)
                // Define the assembly containing the migrations
                .ScanIn(typeof(CreateZipcodeTable).Assembly).For.Migrations())
            // Enable logging to console in the FluentMigrator way
            .AddLogging(lb => lb.AddFluentMigratorConsole())
            // Build the service provider
            .BuildServiceProvider();
    }

To Reproduce
Create an example project using SqlServer, and run in container (for purposes of testing)

docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=yourStrong(!)Password" -e "MSSQL_PID=Evaluation" -p 1433:1433  -d mcr.microsoft.com/mssql/server:2022-latest

Once up and running use the above migrations project with a connect to the database, create an empty database.
Start debugging hasMigrations to apply with start to throw the exception.

Note that this behaviour seems to be related to the in-process runner as this behaviour doesn't happen when using the DotNet CLI utility.

Expected behavior
Migrations are enumerated correctly and applied/skipped.

Information (please complete the following information):

  • OS: Windows 10
  • Platform - .NET 8
  • FluentMigrator version - 5.2.0
  • FluentMigrator runner - "in-process runner"
  • Database Management System - SQLServer
  • Database Management System Version - SqlServer 2022
@jzabroski
Copy link
Collaborator

Can you provide an SSSCE http://sscce.org/

This example is not compile-able but its worth nothing everything that the .NET Cli does is using the DI extensions under the hood. There is no magic, so it is likely a bug in your code somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants