Nucs / JsonSettings

This library simplifies creating configuration for your C# app/service by utilizing the serialization capabilities of Json.NET to serialize nested (custom) objects, dictionaries and lists as simply as by creating a POCO and inheriting JsonSettings class.
MIT License
76 stars 18 forks source link

System.NullReferenceException #2

Closed ghost1372 closed 6 years ago

ghost1372 commented 6 years ago

i updated my project library to 1.0.4 but i get error (if my config.json does not exist this happend) System.NullReferenceException: 'Object reference not set to an instance of an object.'

Nucs commented 6 years ago

Hey Mahdi, could you please provide the stacktrace and the code you used to settings?

ghost1372 commented 6 years ago
SettingsBag Settings { get; } = JsonSettings.Construct<SettingsBag>("config.json").EnableAutosave().LoadNow();

        public MainWindow()
        {
            InitializeComponent();
            Settings.AsDynamic().key = "wow"; //BOOM! SAVED!
            Settings["key"] = "wow two"; //BOOM! SAVED!
        }

Exception thrown: 'System.NullReferenceException' in nucs.JsonSettings.dll An exception of type 'System.NullReferenceException' occurred in nucs.JsonSettings.dll but was not handled in user code Object reference not set to an instance of an object.

just create new project and update jsonsettings to lattest version and you can see there is a problem This is a problem with version 1.0.4 Version 1.0.3 works well

Nucs commented 6 years ago

Thanks for reporting, I've fixed it - the file was opened using Truncute and not OpenOrCreate and therefore nothing was opened resulting in null.

I published it to release 1.0.5. Please confirm that it works for you.

ghost1372 commented 6 years ago

tnx fixed