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

GetDiscoveredScripts throws a NullReferenceException when using WithScriptsAndCodeEmbeddedInAssembly #6

Open
blankensteiner opened this issue Mar 10, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@blankensteiner
Copy link

Hi

Let's start with the code (using the latest version of DbUp in a .NET Core 3.1 application).

var upgradeEngine = DeployChanges.To
                    .SqlDatabase("snip")
                    .LogToConsole()
                    .WithScriptsAndCodeEmbeddedInAssembly(Assembly.GetExecutingAssembly())
                    .Build();

Console.WriteLine("Discovered scripts:");
foreach (var script in upgradeEngine.GetDiscoveredScripts())
    Console.WriteLine("\t" + script.Name);

Calling GetDiscoveredScripts or GetExecutedButNotDiscoveredScripts will both call GetDiscoveredScriptsAsEnumerable, which in turn will call EmbeddedScriptAndCodeProvider.GetScripts which will then call ScriptsFromScriptClasses. This is a problem since it will call DatebaseConnectionManager.ExecuteCommandsWithManagedConnection and here the 'transactionStrategy' field is null, because OperationStarting has never been called.

@blankensteiner blankensteiner added the bug Something isn't working label Mar 10, 2020
@narve
Copy link

narve commented Mar 19, 2020

Confirmed, this is a showstopper right now :(

Did this work in 4.2.0?

Update: Worked in 4.2.0, downgrading.

@ZJouba
Copy link

ZJouba commented Sep 27, 2020

@jhumphries83
Copy link

Downgrading to dbup-sqlserver 4.2.0 didn't work for me. In fact the GetDiscoveredScripts method doesn't exist in 4.2.0.

It looks as though it was introduced in 4.3.0 and has not worked with WithScriptsAndCodeEmbeddedInAssembly since then.

@droyad droyad transferred this issue from DbUp/DbUp Jan 30, 2024
@JasonTheProgrammer
Copy link

It's possible to work around this issue by triggering initialisation of the 'transactionStrategy' field.

var upgradeConfig = DeployChanges.To
                    .SqlDatabase("snip")
                    .LogToConsole()
                    .WithScriptsAndCodeEmbeddedInAssembly(Assembly.GetExecutingAssembly())
                    .BuildConfiguration();
var upgradeEngine = new UpgradeEngine(upgradeConfig);

// This ultimately ensures 'transactionStrategy' is no longer null.
using var disposableOperation = upgradeConfig .ConnectionManager.OperationStarting(
   new DbUp.Engine.Output.NoOpUpgradeLog(),
   new List<SqlScript>());

Console.WriteLine("Discovered scripts:");
foreach (var script in upgradeEngine.GetDiscoveredScripts())
    Console.WriteLine("\t" + script.Name);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Bugs
Development

No branches or pull requests

5 participants