How do I connect the App.config?
Question.
1. How do I connect the App.config?
2. Did I connect the App.config correctly?
I am trying to connect App.config.
When I try to extract data from App.config I connect null.
Description.
Settings
Debugging
void ReadConfig() { var con = ConfigurationManager.ConnectionStrings["App"]; var path = ConfigurationManager.GetSection("countoffiles"); string configvalue1 = ConfigurationManager.AppSettings["countoffiles"]; string configvalue2 = ConfigurationManager.AppSettings["logfilelocation"]; }
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="countoffiles" value="7" /> <add key="logfilelocation" value="abc.txt" /> </appSettings> </configuration>
I use:
- LINQPAD 6.9.15x64.
Comments
I don't think app.config files are supported under .NET Core and .NET 5. Have you had any luck getting this to work in Visual Studio, when targeting .NET Core or .NET 5?
1. What platform does Linqpad use by default (Framework, .NET Core, .NET 5)?
2.I want to implement an example from
docs.microsoft.com
.Does it require a
config
Linqpad file?Or can I do without the 'config' file?
How do I do this in
Link to the example.
LINQPad 6 targets .NET 5 and .NET Core 3.x.
LINQPad 5 targets .NET Framework. If you want to use .NET Framework, run LINQPad 5.
Regarding logging and tracing in .NET Core:
https://docs.microsoft.com/en-us/dotnet/core/diagnostics/logging-tracing
.Net Core, 5 and 6 do use an app.config if present. I managed to add my own by creating a file named LINQPad7.Query.dll.config and adding it to my list of references for the query.
Hi,
I manage to use app.config with this code
public static void InitialiseConfiguration(params string[] configPath)
{
string configPathLocal = Path.Combine(configPath);
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configPathLocal);
typeof(ConfigurationManager)
.GetField("s_initState", BindingFlags.NonPublic | BindingFlags.Static)
.SetValue(null, 0);
}
Cheers
JoeAlbahari it's possible to implement It in LinqPad?
Thanks