C# Windows app updating JSON file error.

Spike UK
Spike UK used Ask the Experts™
on
I am writing a application that reads and updates a JSON file.
I can read it OK but when I try to updaed it, I get the following error:
Severity      Code      Description      Project      File      Line      Suppression State
Error      CS0656      Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'

The code I am using to update is:

 public bool SetSystemOptions(int MinRxLThreshold, ref string messag)
        {
            SysSettings SysSetting;
            bool Success = true;
            string json = File.ReadAllText("settings.json");
            dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
            jsonObj[0]["Password"] = "new password";
            string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
            File.WriteAllText("settings.json", output);

            return Success;
}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fernando SotoRetired
Distinguished Expert 2017

Commented:
Please post a sample json file that the code is using. Thanks.

Author

Commented:
{
    "min_scans": 5,
    "password": 5,
    "user": 40,
    "threshold_meters": 50,
    "min": 1000,
    "max": 100,
    "invalidthreshold": 120,
    "invalid_drop": false,
    "filter_params": false
}
Fernando SotoRetired
Distinguished Expert 2017

Commented:
Try changing the following line in your code from this
 jsonObj[0]["Password"] = "new password";

Open in new window

to this
 jsonObj["Password"] = "new password";

Open in new window

Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Author

Commented:
Tried that- didn't help. Any other ideas?
Fernando SotoRetired
Distinguished Expert 2017

Commented:
In the solution I posted I used the Jason structure you posted and got the result. So what did it returned In your project and what where you expecting.

Author

Commented:
Istill get the error (when I try to cmpile the project):

Severity      Code      Description      Project      File      Line      Suppression State
Error      CS0656      Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'
Retired
Distinguished Expert 2017
Commented:
Please see this Microsoft link on this issue.  Compiler Error CS0656

Author

Commented:
Solved
Fernando SotoRetired
Distinguished Expert 2017

Commented:
Please supply the resolution for others in the future having the same issue.

Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial