I'm building a small project to understand F# better. As part of it, I want a function "myAppSettings" that uses System.Configuration.ConfigurationManager to read settings from the AppSettings.config file. I put this in a separate file in my solution called myAppSettings and it looks like this:
namespace foo.bar
open System
open System.Configuration
module myAppSettings =
let read key mandatory =
let appSettings = ConfigurationManager.AppSettings
let value = appSettings key
if mandatory && String.IsNullOrEmpty(value) then
failwith "bad hombres"
value
This does not compile however, I get the error:
Error 1 The namespace or module 'ConfigurationManager' is not defined
I know that that object is in System.Configuration (use it all the time from C#) so I must have syntax wrong somewhere, but where?
I also tried:
let appSettings = new ConfigurationManager.AppSettings
let value = appSettings key
which then found the ConfigurationManager (the new keyword helped) but then objected to the "let value":
Error 1 Incomplete structured construct at or before this point in expression
I want to understand the two error messages and the right way to access the settings in the app.config file.