How can we help you today? How can we help you today?

Work BuildFromDifferences Null reference exception

I am trying to call the BuildFromDifferences on the following code, but it is failing, throwing a null reference exception:

public void GenerateScriptsToFolder(Differences differences, string file)
{
foreach (var diff in differences)
{
diff.Selected = (diff.Type != RedGate.Shared.ComparisonInterfaces.DifferenceType.Equal
&& diff.Type != RedGate.Shared.ComparisonInterfaces.DifferenceType.OnlyIn1
&& diff.DatabaseObjectType != ObjectType.Schema);
}

var work = new Work();
work.BuildFromDifferences(differences, Options.IncludeDependencies, true);
using (var stream = work.ExecutionBlock.GetStream())
{
using (var fileStream = File.Create(file))
{
stream.Seek(0, SeekOrigin.Begin);
stream.CopyTo(fileStream);
}
}
}

I am calling this function sending the differences (I can see them correctly when I create a datatable with the information), however, on the BuildFromDifferences, it is throwing a null reference exception without any more details.

Any idea why? is something wrong on this?

Best Regards.
briancollog
0

Comments

3 comments

  • Rob C
    Hi,

    Sorry that you're experiencing this problem. Which version of the SDK are you using? If you try it with the latest version of the SDK, does the problem still occur? Here's a download link if you need it - download link
    Rob C
    0
  • briancollog
    Sorry, I was doing some testing today and found that the problem is that I was disposing the database object prior to calling the method.

    Thanks.
    briancollog
    0
  • Rob C
    No problem! I'm pleased that everything's working now.
    Rob C
    0

Add comment

Please sign in to leave a comment.