0

I have one .Net Core Application, let's say somethingSite in which I have included one Class Library Project, let's say CommonActivity. In this Class Library project, I have referenced two DLLs, 1. BAL.dll and 2.DAL.dll.

Now when called make to BAL class say BusinessLayer, it will call the class DataAccessLayer available in DAL.dll. And this DataAccessLayer trying to access Connection String named "con".

I have added the app.config file in my included Class Library (CommonActivity). But the issue is DAL is not able to Pick the Connection String "con" from App.config file and throwing an error "Object is not set to an instance".

can anyone guide me what and where I am doing wrong here?

  • App.Config isn't a thing in .NET Core anymore. Make your class library receive it's configuration via parameters instead of having the library directly pull it from configuration. That keeps your class library flexible. See [my answer here](https://stackoverflow.com/a/61543083/1139830) for further details on how to do that. Then your ASP.NET Core site can read the connection string from appsettings.json at startup time, and pass it to the library at app startup time when you're wiring up dependency injection. – mason Sep 07 '22 at 12:25
  • The config of the library doesn't help. Settings are read from the hosting assembly config. In your case as it seems to be a web project so setting needs to be there in the web.config. In case of a core project its the appsettings.json instead of the web.config. – Ralf Sep 07 '22 at 12:35
  • Now, Asp.net core use `appsettings.json` instead of `app.config` to configure, `ConnectionString` should be configured in `appsettings.json`, You can refer to this [Docs](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-6.0) to check more information about configuration in asp.net core – Xinran Shen Sep 08 '22 at 09:05

0 Answers0