Click here to Skip to main content
15,615,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI, i'm try to extract some keys from the app.config file in visual studio mac, but isn't working.

using System;
using System.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace PrimoFramework
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {

            Console.WriteLine(ConfigurationManager.AppSettings.Get("Browser"));
            Console.WriteLine(ConfigurationManager.AppSettings.Get("Username"));
            Console.WriteLine(ConfigurationManager.AppSettings.Get("Password"));

        
        }
    }
}


This is my app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <appSetting>

       <add key = "Browser" value="Chrome"/>
         <add key = "Username" value="nimanikravan@gmail.com"/>
          <add key = "Password" value="1995!Mille"/>

   </appSetting>
        
        
</configuration>


I create the app.config file adding a new file at the project and i tried to link it with my file.cs using the relative Nuget Package "system.configuration".

What I have tried:

Using the method WriteLine for see if all was working I received this message on the output:

Quote:
This is my output:

Console.WriteLine(ConfigurationManager.AppSettings.Get("Browser"));
No return value.


Is here anyone how knows how to solve the problem with the mac?
Posted
Updated 20-Apr-22 0:16am
Comments
0x01AA 20-Apr-22 6:34am    
The tag in the xml needs to be <appSettings></appSettings>

1 solution

The key in your App.config file should be appSettings with a trailing "s".
 
Share this answer
 
Comments
Nima Nikravan 20-Apr-22 6:23am    
Oh thanks, nice one, but still not working.
Richard MacCutchan 20-Apr-22 6:49am    
I do not have a Mac system but it works fine in Windows. You need to use the debugger to find out what is happening.
Nima Nikravan 20-Apr-22 12:11pm    
257640 <no name=""> 0x0 in System.Threading.ManualResetEventSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
257657 <no name=""> 0x0 in PrimoFramework.UnitTest1.TestMethod1() Line 16 at /Users/nimanikravan/Projects/PrimoFramework/PrimoFramework/UnitTest1.cs:16,13
257662 Worker Thread 0x0 in Interop.Sys.Poll(System.Runtime.InteropServices.SafeHandle fd, Interop.Sys.PollEvents events, int timeout, out Interop.Sys.PollEvents triggered)
257664 <no name=""> 0x0 in System.Net.Sockets.SocketAsyncEngine.EventLoop()
257665 <no name=""> 0x0 in System.Threading.ManualResetEventSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)

Really don't know how to use this :(
Richard MacCutchan 20-Apr-22 12:18pm    
Sorry, I have no idea what that is about.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900