简体   繁体   中英

Asp.net C# : Error of system can find the file specified when using serialising json values (dictionary)

I have the following code:

Dictionary<string, string> values = new Dictionary<string, string>();
values.Add("key1", "value1");
values.Add("key2", "value2");
string json = JsonConvert.SerializeObject(values);

but it's always throwing an exception:

System can not find the file specified

I've tried your code and It works well.

You should re-check some other cases:

  1. Re-install library using.. Update-Package Newtonsoft.Json -Reinstall
  2. Keep all the files from the bin-folder along with the executable, make sure the reference property "Copy Local" is set to true for Newtonsoft.Json

图片

You should try the following

  1. remove the reference for NewtonSoft from your project
  2. uninstall it if its installed from under 'Manage Nuget Packages' of your project
  3. Install latest newtonsoft

Run your code again and it should work

why does this error occur

Normally when you copy the project from another system, the referenced are there in the project files but the files themselves do not exist. You can restore the nuget packages to resolve the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM