Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 使用dotnet run--project选项时获取NullReferenceException_.net_Visual Studio_Command Line Interface_Dbup - Fatal编程技术网

.net 使用dotnet run--project选项时获取NullReferenceException

.net 使用dotnet run--project选项时获取NullReferenceException,.net,visual-studio,command-line-interface,dbup,.net,Visual Studio,Command Line Interface,Dbup,我试图使用dotnet run--project语法运行我的项目文件,但我得到一个NullReferenceException,如图所示: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at DbUp.Engine.UpgradeEngine.PerformUpgrade() 以下是我的主要观点: static int Ma

我试图使用
dotnet run--project
语法运行我的项目文件,但我得到一个NullReferenceException,如图所示:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at DbUp.Engine.UpgradeEngine.PerformUpgrade()
以下是我的主要观点:

static int Main()
{
    var connectionString =
        "Data Source=.;" +
        "Initial Catalog=MyTable;" +
        "User id=SA;" +
        "Password=<mypasswordhere>;";

    var upgrader =
        DeployChanges.To
            .SqlDatabase(connectionString)
            .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
            .LogToConsole()
            .Build();

    var result = upgrader.PerformUpgrade();

    if (!result.Successful)
    {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine(result.Error);
        Console.ResetColor();
        return -1;
    }

    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine("Success!");
    Console.ResetColor();
    return 0;
}

对于其他人来说,降级到DBUp 4.2.0解决了我的问题

堆栈跟踪真的只有一级深吗(不包括您自己的代码)?在大多数情况下,抛出
NullReferenceException
的代码都有bug。它假设某个东西不是空的,而实际上它是空的。但是,它可能只是“草率”的参数检查,但您提供的唯一可以为null的参数是
Assembly.getExecutionGassembly()
。您应该直接在代码中检查,排除这种可能性,然后与
PerformUpgrade
的作者联系。在运行之前,请尝试运行
dotnet restore
project@MartinLiversage不,不过剩下的只指向我的项目名称。@PavelAnikhouski不,不幸的是,事实并非如此work@MartinLiversage似乎这里的问题是
Assembly.getExecutionGassembly()
。奇怪的是,当在visualstudioi中进行调试时,发现dbupsqlite存在相同或类似的错误。降级只是导致未找到sqlite dll的错误。实际问题是由于我的程序集中缺少Microsoft.Data.Sqlite nuget引用造成的。DbUp在预防性错误检查/报告方面似乎不是最好的。
dotnet run --project <full path to my .csproj file>