Search code examples
linqpad

Read ConfigurationManager.AppSettings for LinqPad 8


I have a problem with the read of configurationmanager.appsettings, I want to debug with LINQPad 8 a program with a DLL library that I create. The problem is that the DLL library take a URL of a webserver from the config file (app.config if is a desktop software or web.config if it's a web app) but I don't know how to do this in linqpad 8.

In my DLL I use this instruction to take the URL of webserver (after I call the API from this URL):

string url = ConfigurationManager.AppSettings["Url"];

How can I fix it? Thanks.

The code for LINQPad 8 or the code of LINQPad.config/appsettings.json takes that variable from ConfigurationManager.AppSettings.


Solution

  • The instructions may differ with Linqpad version 5 and lower, but this works for me with versions 6, 7 and 8.

    Copy your app.config and save it with the correct name which depends on your version of LinqPad.

    • For LinqPad 6 this should be LINQPad6.Query.dll.config
    • For LinqPad 7 this should be LINQPad7.Query.dll.config
    • For LinqPad 8 this should be LINQPad.Query.dll.config

    In your query, add this file to your references (i.e. F4, Additional References/ Browse)

    Your query should now work.

    If you don't have an existing app.config, you can just create one like below

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="Url" value="https://www.google.com" />
      </appSettings>
    </configuration>