Avatar of Spike UK
Spike UK
Flag for United Kingdom of Great Britain and Northern Ireland asked on

C# Windows app updating JSON file error.

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;
}
* compilerC#JSON

Avatar of undefined
Last Comment
Fernando Soto

8/22/2022 - Mon
Fernando Soto

Please post a sample json file that the code is using. Thanks.
Spike UK

ASKER
{
    "min_scans": 5,
    "password": 5,
    "user": 40,
    "threshold_meters": 50,
    "min": 1000,
    "max": 100,
    "invalidthreshold": 120,
    "invalid_drop": false,
    "filter_params": false
}
Fernando Soto

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

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Spike UK

ASKER
Tried that- didn't help. Any other ideas?
Fernando Soto

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.
Spike UK

ASKER
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'
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Fernando Soto

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Spike UK

ASKER
Solved
Fernando Soto

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

Thanks