我遇到的問題是當我運行程序時,我得到一個“System.NullReferenceException”異常。不確定是什麼問題。此問題也不允許我使用dnx啟動數據遷移。

在此處輸入圖像描述

在此處輸入圖像描述

#config.json

 {
  "Data": {
  "DefaultConnection": {
  "Connectionstring": "Data Server=.\\ERKANDEMIR5E91;Initial Catalog=RegistrationDB;Integrated Security=True;"
      }
   }
}

scoolDbContext.cs

#config.json

 {
  "Data": {
  "DefaultConnection": {
  "Connectionstring": "Data Server=.\\ERKANDEMIR5E91;Initial Catalog=RegistrationDB;Integrated Security=True;"
      }
   }
}

Statup.cs

#config.json

 {
  "Data": {
  "DefaultConnection": {
  "Connectionstring": "Data Server=.\\ERKANDEMIR5E91;Initial Catalog=RegistrationDB;Integrated Security=True;"
      }
   }
}

在此處輸入圖像描述

一般承認的答案

你應該修復代碼

public Startup (IHostingEnvironment env)
{
    //setup configuration sources
    Configuration = new Configuration()
        .AddJsonFile("config.json")
        .AddEnvironmentVariables();
}

public Startup (IHostingEnvironment env)
{
    //setup configuration sources
    Configuration = new Configuration()
        .AddJsonFile("config.json")
        .AddEnvironmentVariables();
}

或者

public Startup (IHostingEnvironment env)
{
    //setup configuration sources
    Configuration = new Configuration()
        .AddJsonFile("config.json")
        .AddEnvironmentVariables();
}



許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因