Friday, 15 June 2012

c# - ConfigurationErrorsException when reading app.config setting -


I am trying to test a page for a webshop, I want to use API client with molly .

  • I have some problems when I try to test in the normal Visual Studio:

    1. I can not see API client in Visual Studio for the web
    2. There are some errors: in the program.cs

        Moleclient moley client = new molly client (); MollieClient.setApiKey (ConfigurationManager.AppSettings ["mollie_api_key"]);  

    In the app.congfig file, I find:

      App Settings configSource = "localApp.config" Gt; & Lt; Add Key = "mollie_api_key" value = "test_1234" /> & Lt; / AppSettings & gt;  

    For obvious reasons, I changed my API key to a duplicate key, but this code gives an error, I can not find the key and its value that I had found One simple solution was:

      Mclealant Molly Client = New Molly Client (); MollieClient.setApiKey ("Test_1234"); It works, the console shows me the loader ... but it gives an error here;  
      HttpWebRequest request = (HttpWebRequest) WebRequest.Create (url);     

    I get a Configuration Error Exposure , I thought the value of the request is empty and I think the reason for the problem

    But should the following line be fixed? (

  • It seems that you have added the attribute by mistake, To read the settings from the external file, besides the one file you do not have, the correct syntax for this element is file , as you can find on the app settings / <>

    This will be the reason for the exception. Remove configSource and you will be okay.


    No comments:

    Post a Comment