Giter Club home page Giter Club logo

fsharp.configuration's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fsharp.configuration's Issues

TypeInitializationException at runtime

I added the library via nuget. I followed the example, and at design time I get the intellisense for the tags I put in my app.config file inside the node.

When I try to run the program, I get a generic TypeInitializationException with no details. Commenting out the type provider solves the problem.

I am using F# runtime 4.4 with .Net 4.5.2 in VS2015. The project type is a normal F# Console Application.

FSharp.Configuration did not read settings specified in Azure Website

I didn't want to check in sensitive appSettings in my web.config file, so I used the file attribute on my appSettings to specify them through a separate file which only exists locally. I also specified the keys with empty values in my web.config file so I could use the web.config for the type provider.

Then on my Azure Web Site I specified the "production" values for my app settings in the management portal and thought they would be read by the type provider, but they weren't. I think the reason might be that the settings I provided are injected in run time and not added to the actual file, but that's just me guessing.

The app setting value 012 is parsed as integer and becomes 12

When an app setting value has a leading zero "0" for examle "CatalogId" "012" the type AppSettings has a property "CatalogId" of type int and the value 12.

<appSettings>
    <add key="CatalogId" value="012" />
</appSettings>

It should be instead of type string so that the leading zero is not lost, because 12 is not the same as 012.

Actually I have to insert a leading character for example "z012" as a value to force "CatalogId" to be of type string.

Robert Niemann

AppSettings - scripts & redirection

I have an .fs file which references the AppSettings provider. If I #load this file from a script, the code does not compile (I imagine because the TP is trying to locate the properties from FSI's app.config). Is there any way around this? The redirection support is only for runtime, not design time.

tryReadNonEmptyTextFile Loops Indefinitely if File is not Found

Description

FSharp.Configuration.Helper.File.tryReadNonEmptyTextFile loops indefinitely if file is not found.

and loop attemptsLeft = async {
let attempt = maxAttempts - attemptsLeft + 1
match tryOpenFile filePath with
| Some file ->
try
use reader = new StreamReader (file)
match attemptsLeft, reader.ReadToEnd() with
| 0, x -> return x
| _, "" ->
printfn "Attempt %d of %d: %s is empty. Sleep for 1 sec, then retry..." attempt maxAttempts filePath
return! sleepAndRun attemptsLeft
| _, content -> return content
finally file.Dispose()
| None ->
printfn "Attempt %d of %d: cannot read %s. Sleep for 1 sec, then retry..." attempt maxAttempts filePath
return! sleepAndRun attemptsLeft }

Repro steps

open FSharp.Configuration

type Config = YamlConfig<YamlText=@"SampleConfig:",ReadOnly=true>

// loops indefinitely
Config().Load("./some/nonexistent/config.yml")

Expected behavior

tryReadNonEmptyTextFile eventually stops trying to load the file.

Actual behavior

Sample fsi output:

Attempt 1 of 5: cannot read ./some/nonexistent/config.yml. Sleep for 1 sec, then retry...
Attempt 2 of 5: cannot read ./some/nonexistent/config.yml. Sleep for 1 sec, then retry...
Attempt 3 of 5: cannot read ./some/nonexistent/config.yml. Sleep for 1 sec, then retry...
Attempt 4 of 5: cannot read ./some/nonexistent/config.yml. Sleep for 1 sec, then retry...
Attempt 5 of 5: cannot read ./some/nonexistent/config.yml. Sleep for 1 sec, then retry...
Attempt 6 of 5: cannot read ./some/nonexistent/config.yml. Sleep for 1 sec, then retry...
Attempt 7 of 5: cannot read ./some/nonexistent/config.yml. Sleep for 1 sec, then retry...
Attempt 8 of 5: cannot read ./some/nonexistent/config.yml. Sleep for 1 sec, then retry...

Yaml LoadAndWatch and Parse Errors.

When I call Yaml.Load on an unparseable yaml file, I get an exception that I can catch and handle. That's perfect. When I call Yaml.LoadAndWatch and I then change the file to something unparseable, the exception that is generated is thrown in some background thread created by the filesystemwatcher and is not something I can catch (short of an unhandledthreadexception handler).

I initially looked at the code to see if I could modify things so that the Changed events would return a disc union of Success|Error(exn) but found that was an awfully complicated change.

I don't like the idea of eating the parse exception in LoadAndWatch, but I might be able to argue that an unparseable change isn't a change in the sense the method implies. Id prefer to find a way to get the Changed event handler to let me know that it failed, but I'm not even sure that's possible from what I was reading. Would consuming the exception in the watcher callback be appropriate?

Does anyone else have any better ideas on how to deal with parse exceptions in the LoadAndWatch callbacks?

Add TP for embedded files

It would be nice if a TP for embedded files could be added, so that you can get intellisense completions and compile-time checking of file names.

It may be a bit problematic, in that a TP doesn't see the project system, and can't really load the assembly that is being compiled. :)
The simplest way to do it is probably to just scan the fsproj file for embedded files.

The properties could be of byte array or stream?

Internal error while opening FSharp.Configuration

If I try to open FSharp.Configuration namespace after loading FSharp.Configuration (and SharpYaml), then I get the following error:

error FS0192: internal error: CreateFile(0x80070003)

The same happens if I execute the statement type Settings = FSharp.Configuration.AppSettings<"app.config">

The field, constructor or member 'Test2' is not defined

I have attempted to reproduce exactly the example from the documentation.

My code (in fsx file) is:

#r "fsharp.configuration/lib/net40/FSharp.Configuration.dll"
#r "System.Configuration.dll"
open FSharp.Configuration

type Settings = AppSettings<"app.config">
Settings.Test2

The intellisense correctly detects the properties on Settings but when I evaluate the script I get an error

The field, constructor or member 'Test2' is not defined

Have I done something wrong?

0.5.5 causes YamlProvider to throw on type initializer

When upgrading to 0.5.5 the following code gives errors in Visual Studio at editing time:

type WebConfig = YamlConfig<"Web.yaml">

The error is:
The type provider 'FSharp.Configuration.ConfigTypeProvider+FSharpConfigurationProvider' reported an error: The type initializer for '<StartupCode$FSharp-Configuration>.$FSharp.Configuration.YamlConfigTypeProvider' threw an exception

The input is a simple:

EventStore:
    ConnectionString: tcp://admin:[email protected]:1113

Although we tried debugging this with @vasily-kirichenko on slack, it seems to work when manually doing it in the test project (verified this myself as well)

However, I have reproduced it by changing the test project to use 0.5.5 from NuGet and using the above configuration file.

You clone this: https://github.com/CumpsD/FSharp.Configuration and open FSharp.Configuration.Tests.sln. You should see in YamlProvider.Tests.fs it gives errors

Better exception/error mesages

If expected connection string entry is missing at run-time the type provider throws

System.NullReferenceException: Object reference not set to an instance of an object.
at FSharp.Configuration.AppSettingsTypeProvider.getConnectionString(String key) in
D:\git\FSharp.Configuration\src\FSharp.Configuration\AppSettingsProvider.fs:line 28

It would be nice if it can raise more meaningful error. Something like
raise <| System.KeyNotFoundException(sprintf "Cannot find name %s in section of config file." "AdventureWork")

I do similar thing in FSharp.Data.SqlClient
https://github.com/fsprojects/FSharp.Data.SqlClient/blob/master/src/SqlClient/Configuration.fs#L88

Working with new AspNetCore project.josn & hosting.json

I wanted to start a discussion to see about interest in extending the library to cover AspNetCore's project.json and hosting.json configuration files. Though the AspNet team seems to still be shaking the kinks out of what goes where, having these configs pre-baked into the library would ease the ultimate transition to AspNetCore.

[YamlConfig] Allow optional fields in lists

Langs:
  - Name: F#
    HKT: false
    Cool: true

  - Name: Rust
    HKT: false

  - Name: Haskell
    HKT: true
    Macros: true

would generate:

type Langs_Type() =
  member __.Name: string
  member __.HKT: bool
  member __.Cool: bool option
  member __.Macros: bool option

Hint: see how XmlProvider/JsonProvider from FSharp.Data do the same.

Possibility to override used *.config file

I'm trying to run AppSetting provider (the NuGet package version) from FShap Interactive (version 14.0.23020.0).

I try to give the path in any format:

type Settings = FSharp.Configuration.AppSettings<__SOURCE_DIRECTORY__ + @"/app.config">
type Settings = FSharp.Configuration.AppSettings<__SOURCE_DIRECTORY__ + @"\app.config">
type Settings = FSharp.Configuration.AppSettings<"app.config">

(I was hoping to use the first one to work on both .NET and Mono...)
Visual Studio Intellisense works fine. Settings.ConfigFileName gives the right file name. But trying to get or set the actual values (Settings.MyThingHere) from F# Interactive will raise an exception.
So none of these works. they raise:

 System.Collections.Generic.KeyNotFoundException: Cannot find name RuntimeDBConnectionString in <appSettings> section of config file.
   at FSharp.Configuration.AppSettingsTypeProvider.getConfigValue(String key) in d:\git\FSharp.Configuration\src\FSharp.Configuration\AppSettingsProvider.fs:line 21
   at <StartupCode$FSI_0004>.$FSI_0004.main@() in C:\git\myproject\MyScript.fsx:line 45

I'm trying to debug what happens here, and I think it is trying in runtime use Fsi.exe.config instead of the file I have given. getConfig().AppSettings.Settings.[key] fails as AppSettings Count is zero.

AppSettingsProvider throws ArgumentException when used in web project

I'm trying to use the AppSettingsProvider to access some web.config values from an MVC project but this code:

open FSharp.Configuration
type Settings = AppSettings<"web.config">
let test = Settings.MyConfigValue

throws the following exception:

System.ArgumentException was unhandled by user code
Message: An exception of type 'System.ArgumentException' occurred in System.Configuration.dll but was not handled in user code
Additional information: exePath must be specified when not running inside a stand alone exe.

Redirecting appends ".config" at the end

Updating this issue. Currently you have to redirect to a specific DLL or executable using the SelectExecutableFile method. It would probably be simpler to offer the ability to redirect to any .config file - especially if you are in e.g. a web situation and want to get at something like web.config (or any other .config file).

AppSettings - Add support for getting default values

I have have designed a library with an internal app.config file. When I reference that library in other project that does not have its app.config, then I would like to use a default setting value.

example ussage:

let defaultOrNot = Settings.HostPort 8050

ResXProvider cannot read any values from the embedded resource.

At runtime, ResXProvider references the local path of the build environment.
ResXProvider generates the following code.

ResXProvider.readValue "E:\\repos\\FsYaml2\\FsYaml\\Resources.resx" "mustBeSequence" :?> string

An exception occurs because Resources.resx does not exist at runtime.

Similar to #46

Unable to install FSharp.Configuration NuGet package into an F# project, works OK with C#

If I create a new F# library project using VS 2013 and try to install FSharp.Configuration NuGet package, I am getting the following error:

PM> install-package FSharp.Configuration
Installing 'FSharp.Configuration 0.5.0'.
Successfully installed 'FSharp.Configuration 0.5.0'.
Adding 'FSharp.Configuration 0.5.0' to Library1.
No exact match found for removing reference 'SharpYaml'. Trying case-insensitive search...
Failed to find match for removing reference 'SharpYaml'.
Uninstalling 'FSharp.Configuration 0.5.0'.
Successfully uninstalled 'FSharp.Configuration 0.5.0'.
Install failed. Rolling back...
install-package : Failed to add reference to 'SharpYaml'.
At line:1 char:1

  • install-package FSharp.Configuration
  • - CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    - FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
    
    

If I create an empty C# library project, then everything works fine.

Reload/Event for updating config during runtime

I am looking into using the Configuration type provider to contain logging configuration.
Logging levels and loggers might require a dynamic reconfiguration during runtime. This is what I am currently achieving using log4net.
It would be nice to have support to reload automatically and also for a event when the configuration file is updated while the app is running.

Trying to read resx files from wrong folder?

This might just be me having configured something wrong... The project works fine locally but the resource file reader breaks when I deploy to test environments.

I am trying to figure out where the Resource type provider is finding the filepath from. Locally everything works fine, but when I deploy my project ResXProvider seems to try to read the file from a path on my buildserver. Everything works if I actually go and put the resource file in the buildpath folder, so there is only some issue with where the system tries to go and find the resource file.

System.IO.DirectoryNotFoundException: Could not find a part of the path 'E:\TeamCity\BuildAgent3\work\d15d54883fe35cc\MyProject\Resources1.resx'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.Resources.ResXResourceReader.EnsureResData()
at System.Resources.ResXResourceReader.System.Collections.IEnumerable.GetEnumerator()
at [email protected](Unit unitVar0)
at [email protected](Unit unitVar0)
at Microsoft.FSharp.Collections.SeqModule.TryFind[T](FSharpFunc2 predicate, IEnumerable1 source)
at Microsoft.FSharp.Collections.SeqModule.Find[T](FSharpFunc2 predicate, IEnumerable1 source)
at FSharp.Configuration.ResXProvider.readValue(String filePath, String name) in l:\github\FSharp.Configuration\src\FSharp.Configuration\ResXProvider.fs:line 20

Error on running build.sh

/Users/dave/code/FSharp.Configuration/build.fsx(5,1): error FS0078: Unable to find the file 'NuGet.Core.dll' in any of
 /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5
 /Users/dave/code/FSharp.Configuration
 /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.0/

Sequence of maps not supported?

Nuget:
    Items:  
        -
          name: Mark McGwire
          hr:   65
          avg:  0.278
        -
          name: Sammy Sosa
          hr:   63
          avg:  0.288

Does not seem to work. Seems to be valid yaml. Is there something I'm missing?

Yaml merge syntax

Given the following YAML:

Default: &Default
  Db:
    ConnectionString: Data Source=localhost;Initial Catalog=;Integrated Security=True;Application Name=


Test: &Test
  Environment: Test
  <<: *Default


ActiveConfig:
  <<: *Test

I would think that I should access the desired key like this:

open FSharp.Configuration

type Config = YamlConfig<"Config.yaml">

let config = Config ()

let value = config.ActiveConfig.Environment

But, as it turns out, the resulting type is structured like this:

let value = config.ActiveConfig.``<<``.Environment

Am I missing something? Obviously using the << property is not logical or convenient.

AppConfig returns null

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

Problem with floating point scalars

When i try to define floating point numbers in yaml files type provider reports following error:
'FSharp.Configuration.ConfigTypeProvider+FSharpConfigurationProvider' reported an error: Input string was not in a correct format.

Example yaml file (issue reproduces):

Test:
    AFloatingPointNumber: 0.1

This works fine:

Test:
    AIntegerNumber: 1

URLs are read in as int from app.config

I've tried to configure URIs, suchs as

    <add key="TestUri" value="http://fsharp.org" />

and it is read in as int.
I am not sure if it is a good idea to try to parse URIs as URI or not, or if it should be kept as a string, or if the workaround is to use a connection string for it, so as I don't really know what a good spec would be I guess it's better to submit an issue than a failing test...

This passes

    [<Test>] 
    let ``Can read url from the connection strings``() =   
        Settings.ConnectionStrings.TestUrl.GetType() |> should equal typeof<string>   
        Settings.ConnectionStrings.TestUrl |> should equal "http://fsharp.org"

This fails (read in as int)

    [<Test>] 
    let ``Can read url from the config file``() =   
        Settings.ConnectionStrings.TestUrl.GetType() |> should equal typeof<string>   
        Settings.ConnectionStrings.TestUrl |> should equal "http://fsharp.org"

Add support for Nested List

I have the following yaml file:


---
  id: "myApp"
  constraints: 
    - 
      - "attribute"
      - "OPERATOR"
      - "value"
  labels: 
    environment: "staging"

and here is the error I get when I use the FSharp.Configuration provider:

"The type provider 'FSharp.Configuration.ConfigTypeProvider + FSharpConfigurationProvider' reported an error: Nested lists are not supported."

Can we add support for Nested list to the FSharp.Configuration provider?

Please let me know.

John Montoya

Allow for more keys in transformed configs than in the one provided for the type provider

I typically use a template.config file as the file provided to my type provider. However, when pushing to other environments we transform the config file, and sometimes this means adding more keys (for example, in my case, I use a different way of licensing NServiceBus in production/staging etc. by providing an extra app-settings in these environments. Currently having more keys in ConfigSection seems to give me an error in runtime when I try to start my app.

System.NullReferenceException: NServiceBus has detected a null reference in your initialization code. This could be due to trying to use NServiceBus.Configure before it was ready. One possible solution is to inherit from IWantCustomInitialization in a different class than the one that inherits from IConfigureThisEndpoint, and put your code there. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at FSharp.Configuration.AppSettingsTypeProvider.getConfigValue(String key) in l:\github\FSharp.Configuration\src\FSharp.Configuration\AppSettingsProvider.fs:line 14

YamlConfigProvider fails when using numbers as keys.

I am trying to read a yaml file there are using numbers as keys eg.

test:
    10: 42
    11: 60

but when i run this script

#if INTERACTIVE
#r "FSharp.Configuration.dll"
#endif

open FSharp.Configuration

let [<LiteralAttribute>] test1 = """
test:
    t1: 42
    t2: 60""" 

let [<LiteralAttribute>] test2 = """
test:
    10: 42
    11: 60""" 

type Config1 = YamlConfig< YamlText = test1> // no error
type Config2 = YamlConfig< YamlText = test2> // error

it fails with
Script.fs(24,16): error FS3033: The type provider 'FSharp.Configuration.ConfigTypeProvider+FSharpConfigurationProvider' reported an error: The input list was empty.
where line 24 are type Config2 = YamlConfig< YamlText = test2> (test1 is just to pin point the problem and do not fail)

Are there a way around that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.