Results 1 to 2 of 2

Thread: [RESOLVED] External appSettings Config Not Working

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    10,601

    Resolved [RESOLVED] External appSettings Config Not Working

    I have a solution with several projects. In my API project I have a service that sends emails via Mailgun. Because I do not want to store the username and password in Git, what I've done is stored them in an external appSettings.config file and ignored that particular file. I'm then referencing the values using:
    Code:
    var username = ConfigurationManager.AppSettings["MailgunUsername"];
    var password = ConfigurationManager.AppSettings["MailgunPassword"];
    My issue is that the AppSettings never has my MailgunUsername or MailgunPassword keys. My gut reaction was that because I'm trying to test the service via a unit test project, perhaps I need to add the same external appSettings.config to the unit test project, but that didn't work either.

    Then I thought that perhaps I've setup the config wrong, but I've gone through several examples online and it looks right.

    This is what my Web.config (API project) and app.config (unit test project) file's have for the appSettings:
    HTML Code:
    <appSettings file="AppSettings.config">
      <add key="webpages:Version" value="3.0.0.0" />
      <add key="webpages:Enabled" value="false" />
      <add key="ClientValidationEnabled" value="true" />
      <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      <add key="RuntimeEnvironment" value="Development" />
    </appSettings>
    And this is what my AppSettings.config file (in both projects) looks like:
    HTML Code:
    <appSettings>
      <add key="MailgunUsername" value="-my username here-" />
      <add key="MailgunPassword" value="-my password here-" />
    </appSettings>
    What am I doing wrong here?
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    10,601

    Re: [RESOLVED] External appSettings Config Not Working

    The issue was related to the Copy to Output Directory. Changing it to Copy Always resolved the issue.

    This Stack Overflow response explains why: https://stackoverflow.com/a/34227007/1920035
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width