fsprojects / FSharp.Configuration

The FSharp.Configuration project contains type providers for the configuration of .NET projects.
http://fsprojects.github.io/FSharp.Configuration/
Other
114 stars 63 forks source link

AppConfig returns null #54

Closed phleb3 closed 9 years ago

phleb3 commented 9 years ago

I used nuget to install fsharp.configuration, and followed the instructions. Code:

type Settings = AppSettings<"app.config">

then

let test1 = Settings.TestKey < this returns a null exception

vasily-kirichenko commented 9 years ago

Could you show your app.config?

Muhomorik commented 9 years ago

I am having the same problem on win, VS2013 An unhandled exception of type 'System.NullReferenceException' occurred in FSharp.Configuration.dll Build action : None Copy to output directory: copy if newer

open FSharp.Configuration

// Let the type provider do it's work
type Settings = AppSettings<"App.config">

[<EntryPoint>]
let main argv = 

    printfn "%A" Settings.TestInt
    0 // return an integer exit code

Looks like github doesn't like xml in comments. http://paste.ofcode.org/p4LLKjjYXU22PyuMK2MYzm

Muhomorik commented 9 years ago

Funny thing.. tests are ok. Must be something with setup.

MBrouns commented 9 years ago

Exactly the same problem here.

vasily-kirichenko commented 9 years ago

I'm closing it since no repro have been supplied.

Muhomorik commented 9 years ago

This is a bug. You have unhanded exception in AppSettingsTypeProvider (in my case) in

An unhandled exception of type 'System.NullReferenceException' occurred in FSharp.Configuration.dll

let getConfigValue key 
    ...
    settings.[key].Value

Because var settings length is zero and you are trying to access key that doesn't exist. There should be either check if element exists or exception handling.

Muhomorik commented 9 years ago

And it happens because sometimes (I can reproduce it with 100%) app.config content is not moved to ConsoleApplication1.exe.config file. It looks like it doesn't recognise small changes like formatting and depends on operation order (add code, add config / add config, add code). So removing something big from file, recompiling it and then redo change (ctrl+z) solves the problem for me.