I'm trying to get data from app.config and I always get zero. The App.config is here:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="ExplorerContext" connectionString="metadata=res://*/ExplorerData.csdl|res://*/ExplorerData.ssdl|res://*/ExplorerData.msl;provider=System.Data.SqlClient;provider connection string="Data Source=MYT\SQLEXPRESS;Initial Catalog=Explorer;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
Could someone explain what is wrong, why I cannot get the values,
System.Configuration.ConfigurationManager.AppSettings.Count is always 0
I fogot to specify that I use class library, that I'm trying to check using NUnit project. And this class library calls one more project (class library too) that uses ADO.NET Entity Project.
You're not using AppSettings! Check ConfigurationManager.ConnectionStrings instead.
I forgot to specify that I use class library, that I'm trying to check using NUnit project. And this class library calls one more project (class library too) that uses ADO.NET Entity Project.
You need to put your configuration information into the main app - the app using/calling your class library project with the EF model. .NET configuration does not natively support class library level app.config's.
So in your test environment, the main test harness will need to have these entries in its app.config.
If you insist that your class library assembly have its own config - check out Jon Rista's Cracking the Mysteries of .NET 2.0 Configuration where he explains in great detail how to use the ConfigurationManager.OpenExeConfiguration call to open any arbitrary *.config file and use it within the .NET 2.0 configuration system. It works - but it's more work and I wouldn't really recommend it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With