E
E
Evgeny Semashko2020-05-11 10:33:37
C++ / C#
Evgeny Semashko, 2020-05-11 10:33:37

The variable is not initialized. Why?

Variable not initialized `connectionString`and throws an exception

`System.ArgumentNullException: "Значение не может быть неопределенным.
Имя параметра: connectionString"

`
In the debugger, this variable is set to `null`

var builder = new ConfigurationBuilder();

            builder.SetBasePath(Directory.GetCurrentDirectory());

            builder.AddJsonFile("appsetings.json");

            var config = builder.Build();

            var optionsBuilder = new DbContextOptionsBuilder<ApplicationContext>();

            string connectionString = config.GetConnectionString("DefaultConnection");

            var options = optionsBuilder
                .UseSqlServer(connectionString)
                .Options;

The exception knocks out in the last line

of appsetings.json the parameter is: copy if newer

{
      "ConnectionStrings ": {
        "DefaultConnection": "Data Source=DESKTOP-00IRUOM;Initial Catalog=Practice;Integrated Security=True;Pooling=False;"
      }
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2020-05-11
@evgenysemashko

you have a typo "appsetings.json"
missed t

D
Dmitry Pavlov, 2020-05-11
@Stalker31

hello variable initial value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question