Answered App.config compiled but return null value.

NoviceMer

Member
Joined
Jan 27, 2021
Messages
9
Programming Experience
5-10
Dear Developers,

I would like to clarify my understanding that there is bug with application configuration file provided by Nuget package for System.Configuration.ConfigurationManager. Attempting to follow Microsoft advice but ConfigurationManager.AppSettings["key0"] cannot receive the input.

Below is the code:
XML:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version ="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <appSettings>
        <add key ="key0" value="test"/>
    </appSettings>
</configuration>
At program.cs:
C#:
using System.Configuration;
using System.Collections.Specialized;

static void Main(string[] args)
{
     string sSrvName = ConfigurationManager.AppSettings["Key0"];
}

Your kind sharing is very much appreciated.


Best Regards
 
Last edited by a moderator:
I just downgraded my .NET Core project to 2.0 and ran it again and it worked again. It's worth noting that the NuGet package that was added was version 5.0.0 and the earliest version available is 4.4.0. Version 4.4.1 specifically mentions dependencies for .NET Core 2.0 but later versions do not. They do mention .NET Standard though and, if I remember correctly, .NET Core 2.0 does implement .NET Standard 2.0. Anyway, it works for me targeting .NET Core 2.0, but that is in VS 2019.
 
I just downgraded my .NET Core project to 2.0 and ran it again and it worked again. It's worth noting that the NuGet package that was added was version 5.0.0 and the earliest version available is 4.4.0. Version 4.4.1 specifically mentions dependencies for .NET Core 2.0 but later versions do not. They do mention .NET Standard though and, if I remember correctly, .NET Core 2.0 does implement .NET Standard 2.0. Anyway, it works for me targeting .NET Core 2.0, but that is in VS 2019.
with my current supplied pc always gets "Invalid pointer" when running VS 2019, so i install the Nuget from 5.0.0 to earlier version 4.4.0 still gets null value.

I am looking in implementing streamreader instead

Thank you very much.
 
My recommendation is actually figure out what is preventing VS2019 from running on the machine that has been given to you. Follow that link provided in the other thread. If needed, open a support case with your IT department. Encourage them to open a support case with Microsoft if they can't figure it out with the resource they have with in the IT department. Who knows what else is/will be malfunctioning on your machine without resolving that issue?

While waiting for them to figure it out, install VirtualBox or use Hyper-V, and then install VS2019 within a guest Win10 OS.

If you really must stick with VS2017, then I would also encourage you to also just stick with .NET Framework, and not go with .NET Core 2.x. .NET Core 2.0 ended support on Oct 1, 2018, and .NET Core 2.2 ended support on Dec 23, 2019. Even .NET Core 2.1 which has been marked as LTS (Long Term Support) is ending this Aug 21, 2021.
 
My recommendation is actually figure out what is preventing VS2019 from running on the machine that has been given to you. Follow that link provided in the other thread. If needed, open a support case with your IT department. Encourage them to open a support case with Microsoft if they can't figure it out with the resource they have with in the IT department. Who knows what else is/will be malfunctioning on your machine without resolving that issue?

While waiting for them to figure it out, install VirtualBox or use Hyper-V, and then install VS2019 within a guest Win10 OS.

If you really must stick with VS2017, then I would also encourage you to also just stick with .NET Framework, and not go with .NET Core 2.x. .NET Core 2.0 ended support on Oct 1, 2018, and .NET Core 2.2 ended support on Dec 23, 2019. Even .NET Core 2.1 which has been marked as LTS (Long Term Support) is ending this Aug 21, 2021.
Dear Skydiver,

Thank you very much for pointing out the EOL of .NET Core, i overlook this part from earlier reading. I will follow your advice.

I have to use Console application .NET Core because need to deploy cross-platform like Linux.

This is the problem why have to go for .NET Core

Can .NET Framework run on Linux?
NET Core is cross-platform and runs on Linux, macOS, and Windows. . NET Framework only runs on Windows.

Grateful!!!
 
Thanks for the correction!

Now I have to go figure out what it was in the app.config/web.config that was case sensitive that could make some things work a little batty when they didn't match-up. Was it the assembly bindings? Was it the connection strings? All I recall now was that I spent about half a day trying to track it down once. All these little oddities in the software we use...
 
The xml in those files is case sensitive, if you're doing something at that level.
 
Yes, XML is obviously case sensitive. It was at the level of the values stored in the attributes that was causing a problem. As I

It was almost along the same lines as SharePoint's XML config files where in some places it wants GUIDs stored to be uppercase, and in other places lowercase, and in other places it doesn't really care.
 
Were you able to get this working? Everything works for me when I compile and run on my Windows system, but when I compile and run inside a linux container the App.config is seemingly not being read. I tried also renaming to 'app.config' in case it might have been a case sensitive issue. Using the latest Visual Studio 2019, c# w/ .net 5.0 .
 
Back
Top Bottom