Good day to all, I have such a problem - there is a console application in which I want to call the ConfigurationManager but in IntelliSense there is no choice of this class.

using System.Configuration; using System.Linq; class Program { static void Main(string[] args) { var context = new TestDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); var roles = context.Roles.ToList(); foreach (var role in roles) { Console.WriteLine("{0} {1} {2}", role.ID, role.Code, role.Name); } Console.ReadLine(); } } 

Please help me figure out what I'm doing wrong? thank

  • What in your understanding is "mvc application"? Report the platform version and project type. - Pavel Mayorov
  • @PavelMayorov MVC: "model-view-controller" - that is, the application model, user interface and user interaction are divided into three separate components. Used in web programming. Did you want to hear this? - Ethernets
  • It’s not quite clear where the Main method in your web application comes from and work with the console - Pavel Mayorov
  • @PavelMayorov "Now I create a test console application, and make a connection in References to mvc with LINQ to SQL Classes" - Ethernets
  • one
    As a result, I get an error saying that there is no such name ConfigurationManager. - Add the full text of the error - Grundy

1 answer 1

You need to add a link to the System.Configuration to the project. The ConfigurationManager class is in it. By default, it is not added to the project. Click in the project with the right button on the Reference, select the AddReference item, in the opened window the list of assemblies will appear. There find System.Configuration and mark it. Should work.

  • using System.Configuration; not suitable? - Ethernets
  • one
    The using directive only says about the need to use the namespace (in theory, you can even do without it, indicating the full names of the classes, but this is inconvenient). You also need to add to the project the assembly itself, which contains this namespace and the class you need. - DreamChild
  • one
    Oh my God. The first thought was the same, but I read that the author added the assembly. The idea that he called using "adding a build" did not even occur ... - Pavel Mayorov
  • @DreamChild Thank you - Ethernets