Preferred way of load application settings in f#

Hi

I have library using netstandard 2 and consuming it from a dotnet core 3.1 app and want to get some settings from settings.json or app.config. How do i do that in F#? What is the preferred way here?

I heard about

  1. using using the configuration builder (like c#), it needs the package FsConfig

type Config = {
processId:int
}
let configurationRoot =
ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(“settings.json”).Build()
let result = appConfig.Get ()

this is somehow giving me this error

System.IO.FileLoadException: ‘Could not load file or assembly ‘TypeShape, Version=8.0.1.0, Culture=neutral, PublicKeyToken=null’. The located assembly’s manifest definition does not match the assembly reference. (0x80131040)’

  1. using a typeprovider Fsharp.Configuration FSharp.Configuration this looks promising but in my dotnet core app it wouldnt work.

open FSharp.Configuration
type Settings = AppSettings<“app.config”>
Settings.FlagsFileSource

Thats what i am getting when i want to access the settings, last line above

System.IO.FileNotFoundException: ‘Could not load file or assembly ‘System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. Das System kann die angegebene Datei nicht finden.’

I added this package “System.Configuration.ConfigurationManager,”

then i got this?

System.TypeLoadException: ‘Could not load type ‘System.Web.Hosting.HostingEnvironment’ from assembly ‘System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.’

Any hints?

Looks like with the new alpha2 version of FSharp.Configuration its working.

Anyway, is this the way to go in F#?

1 Like