Problem reading appSettings

I placed some values in LINQPad.config file's appSettings sections like this:





In the code I was trying to do get the value but no value was returned:

var loadDate = ConfigurationManager.AppSettings["LoadDate"];

What did I do wrong?

Comments

  • The html is not showing up there:
    <appSettings>
    	  <add key="LoadDate" value="5/27/2013"/>
      </appSettings>
  • I tried your exact sample and ConfigurationManager.AppSettings["LoadDate"] returned 5/27/2013.

    I take it you've put the settings into linqpad.config (and not linqpad.app.config?)

    What does the following query return?

    AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
  • it returns
    C:\Users\changc\Desktop\LINQPad.config
  • I know what's wrong. When I double click on the .linq file, it's not working. But if I open LINQPad first then drag the .linq file into LINQPad, it will work.
  • Perhaps you have .linq files associated in Windows with a copy of LINQPad.exe that resides in a different folder.
  • Yes that's right I have a different version on my desktop where I used to run my .linq files. When I removed that old LINQPad.exe and tried to associate the .linq again with the exe that resides in the same folder in my desktop, I found I can't associate it. Is it because LINQPad.exe is a portable program? Is there a better way to associate my .linq files with LINQPad.exe where it's not directly on my desktop? Since now I have more files need to be put in the same folder.( all the config files, lprun.exe)
  • I found I can do it. I just pin where my LINQPad.exe to the taskbar. Then I can associate .linq file from properties' association.

    Thanks!
  • @JoeAlbahari I have a similar problem but the `AppDomain.CurrentDomain.SetupInformation.ConfigurationFile` returns C:\Users\myUser\AppData\Local\Temp\LINQPad5\_orthtqce\nzlyzh\LINQPadQuery.dll.custom.config
    My LinqPad is installed in C:\Program Files\LINQPad5

    I wonder why the config would to somewhere else other than C:\Program Files\LINQPad5\LINQPad.config?

    Thanks.
  • That's a merged config file. LINQPad needed to apply binding redirects to your query, so it read the normal config file, added the binding redirects, and wrote the merged file to a temp location.

    Try creating a new query with no references and default properties. Then AppDomain.CurrentDomain.SetupInformation.ConfigurationFile should return C:\Program Files\LINQPad5\LINQPad.config
  • I tried "... creating a new query with no references and default properties.", and my AppDomain.CurrentDomain.SetupInformation.ConfigurationFile.Dump();
    returns
    C:\Users\dennis\AppData\Local\LINQPad\empty.config

    I also then added a reference to System.Configuration, and I get the same result.


    As per the FAQ, I'm trying to "create a file called linqpad.config in the same folder as LINQPad.exe. Anything you put here applies to all queries (unless you override it in the dialog above). " to have a merged set of settings, but I can't get it to work.

    I set up a new LinqPad exe folder - i.e XCOPY deployed. Running from there, ConfigurationFile.Dump() shows

    C:\Users\dennis\AppData\Local\Temp\LINQPad5\_yhiiwvkz\tzuqwq\LINQPadQuery.dll.custom.config

    I still don't get a merged AppSettings.

    What should the root node of Linqpad.config be? I've tried just

    and also



  • Maybe I'm a bit confused by the FAQ's "unless you override it" and Joe's comment above "That's a merged config file...". Do the settings get "merged" from both sources?
  • Do you have a file called "LINQPad.config" in the folder where LINQPad.exe resides? If so, then AppDomain.CurrentDomain.SetupInformation.ConfigurationFile will return that file. Otherwise, it will return the empty.config file.

    You can also specify a config per query by going to query properties F4 and going to the app.config tab.

    The "LINQPadQuery.dll.custom.config" is indeed a merged config. It should contain everything that's in the LINQPad.config file (or whatever you've specified in query properties) plus binding redirects necessary for you query to function.

  • RE: "Do you have a file called "LINQPad.config" in the folder where LINQPad.exe resides? "
    Yes.
    If the F4 App.config tab is set to "Global default ...", then yes, AppDomain.CurrentDomain.SetupInformation.ConfigurationFile does return that. (If set to "Custom path" then it returns that path)
    But if the tab is set to "Let me type it in", then a temporary path is returned - e.g
    C:\Users\dennis\AppData\Local\Temp\LINQPad5\_nrixxzun\rguhkq\LINQPadQuery.dll.custom.config


    When I was asking about "merged", it's whether or not multiple appSetting sections (from multiple config files) are merged.



  • The only time merging that occurs is when LINQPad has to add binding redirects to your query.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!