I'm trying to get the connectionstring from the json-file to the DAL-class library with:
private static IConfigurationRoot config;
private static string connectionString;
public UserDAL()
{
config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
connectionString = config.GetConnectionString("DefaultString");
}
In the json-file:
{
"ConnectionStrings": {
"DefaultString": "theconnectionstring"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
The error happens when I try to open the connection, so con.Open();