We help IT Professionals succeed at work.

C# Windows app updating JSON file error.

Spike UK
Spike UK asked
on
478 Views
Last Modified: 2017-04-06
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

Fernando SotoRetired
CERTIFIED EXPERT
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
CERTIFIED EXPERT
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

Author

Commented:
Tried that- didn't help. Any other ideas?
Fernando SotoRetired
CERTIFIED EXPERT
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
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Solved
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

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

Thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions