Skip to content

ConfigurationBuilder.Get() NullReferenceException issue in .NET Core3.1 ( Random error ) #5798

@ssashok10

Description

@ssashok10

ConfigurationBuilder NullReferenceException issue

Here is the code which produces the NULL reference issue some times. This code runs in a threading scenario and we are in need to load the JSON file dynamically.

            var configuration = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory() + "/sets")
                .AddJsonFile($"settings.{name}.json", optional: false)
                .Build();
           var result = configuration.Get<Settings>();

The above code works well. However, we are getting the below-mentioned error randomly for the last one month. We have done load testing many times and this code works well. We are not sure when exactly the runtime produces this error and it's random always. Can anyone please let me know if it could be an issue with threads? The code exactly fails on the line "var translations = configuration.Get();"

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions