aloneguid / config

⚙ Config.Net - the easiest configuration framework for .NET developers. No BS.
MIT License
656 stars 86 forks source link

File Not Found With Json File Store #127

Open bevanw opened 2 years ago

bevanw commented 2 years ago

Issue When using .UseJsonFile(), an exception is thrown when a setting is being written to a JSON file and the file does not exist. If the file already exists, the setting will be written correctly.

Issue

Workaround

Environment

Affected Versions:

Issue Reproduction

  1. Create a .NET Framework 4.8 Console Application.
  2. Install Config.Json.Net 4.17.0 NuGet package.
  3. Write a new configuration builder using .UseJsonFile() with a relative/absolute path reference (example code below).
  4. Assign a value to the setting property.

Example:

using Config.Net;

namespace JsonConfigStoreTest
{
    public interface ISettings
    {
        string Setting { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            ISettings settings = new ConfigurationBuilder<ISettings>()
               .UseJsonFile("file.json")
               .Build();

            settings.Setting = "Test";
        }
    }
}
luojunyuan commented 2 years ago

124