I have two projects. One is web & the other is windows forms. Web project connects to database but the windows project throws an exception NullReferenceException reading the connection string.
I am using the same classes to connect both projects. Connection is established using LINQTOSQL.
Here is my Connection string:
<connectionStrings>
<add name="GPSystemConnectionString"
connectionString="Data Source=.;Initial Catalog=GPSystem;User ID=***;Password=***"
providerName="System.Data.SqlClient" />
</connectionStrings>
This is how i am reading it.
string CS = ConfigurationManager.ConnectionStrings["GPSystemConnectionString"].ConnectionString;
(Exception occurs on this line)..... (Object reference not set to an instance of an object.)
Note: i am using same class to connect both projects.... one connects but the other fails.
Please any one help me with this!
Thank you in advance.

ExecutingAssembly. This method is really useful.var configs = new ConfigurationBuilder() .AddXmlFile(Path.Combine(AppContext.BaseDirectory, "same.config")) .Build();check this Configuration Builder