I have a solution containing many projects.
One of the projects is a data access layer Class Library. It uses this line for the connection string which it gets from the web.config of any other project that references it:
private string Constr = ConfigurationManager.ConnectionStrings["DefaultConn"].ConnectionString;
I've added a web.config to a .net core 2 MVC app, but I get this error:
FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=123456'. The system cannot find the file specified.
I've also tried adding the connection string to the appsettings.json file - but it also doesn't help; the full contents of appsettings.json:
{
"ConnectionStrings": {
"DefaultConn": "Server=.;Database=MyDatabase;Trusted_Connection=true;"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
I've found a few articles online dancing around it - but none that can fix this.
How to read web.config file in .Net Core app This one mentions a similar situation and a nuget package - but it doesn't solve the issue for the user.
How to include reference to assembly in ASP.NET Core project This one touches on it but applies to Hangfire only, not a Class Library using ConfigurationManager
How can I do this? Thanks.