Coder Social home page Coder Social logo

Comments (4)

patridge avatar patridge commented on September 23, 2024

If we put an exception handler on the ConfigurationBuilder calls, we can catch the initial parsing exceptions, but I haven't been able to figure out how to avoid a downstream NullReferenceException yet.

private void SetConfigRoot()
{
    var b = new ConfigurationBuilder().SetBasePath(AppDomain.CurrentDomain.BaseDirectory);
    b.AddYamlFile("app.config.yaml", true);
    b.AddJsonFile("app.config.json", true);
    b.SetFileLoadExceptionHandler((fleContext) =>
    {
        // This is hit whenever a config file is present but empty (or entirely comments).
        // Ideally, we would load defaults for an emtpy file and present a warning/error for bad JSON/YAML syntax.
        Resolver.Log.Error($"Error loading file configuration:: {fleContext.Exception}");
        this.ConfigurationRoot = null; // Still blows up later in "[External Code]"!
    });
    this.ConfigurationRoot = b.Build();
}

Error message:

System.NullReferenceException
Message=Object reference not set to an instance of an object.

from meadow.core.

patridge avatar patridge commented on September 23, 2024

Since app.config.* is a weird case, allowing JSON or YAML, I tried an empty YAML file with a populated JSON file.

Oddly, this doesn't appear to fail at all, and it grabs the config from the second JSON source just fine (due to order of adding file providers).

from meadow.core.

patridge avatar patridge commented on September 23, 2024

Even more strange. The reverse is not true. If you have a YAML file full of settings and an empty JSON file, it will still throw an exception and hit the SetFileLoadExceptionHandler action.

from meadow.core.

patridge avatar patridge commented on September 23, 2024

Should be addressed by #187.

from meadow.core.

Related Issues (20)

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.