An unhandled exception of type 'System.NullReferenceException' occurred in Lesson1.exe
Additional information: The object reference does not indicate an object instance.
Why do I get this exception?
Code example:
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}", role.Code, role.Name); } Console.ReadLine(); } The exception crashes in this place:
TestDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); example app.conf :
<connectionStrings> <add name="ConnectionString" connectionString="Data Source=WEBBD\test;Initial Catalog=Web;User ID=test;Password=1234" providerName="System.Data.SqlClient" /> </connectionStrings> I will show clearly what is happening, and that I can not
What did I do wrong?
app.conffile? - Pavel Mayorov