Alan
Alan

Reputation: 822

'System.IO.FileLoadException' with newtonsoft-json

The debugger keeps giving me this 'System.IO.FileLoadException' error message in the output window of Visual Studio everytime I call the toJSONString() method in a dll assembly I had created earlier. See method below. I used NuGet to load and reference the newtonsoft-json.dll library, so why a runtime attempt keeps failing is beyond me.

Object output;
...
public String toJSONString()
{
    String strOut = "";
    if (output != null)
    {
        strOut = JsonConvert.SerializeObject(output);
    }

    return strOut;
}

In the Solutions Explorer window, under References, I checked the path for Newtonsoft.Json which is C:\temp2\DataTables_Examples\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll. That dll file does exist there. I don't know why the app doesn't see it? Any help would be appreciated.

Upvotes: 2

Views: 3199

Answers (2)

Garamaru
Garamaru

Reputation: 116

Have you any software opened, that is viewing the library or a folder of it? (like NotePad++ or whatever) Also it would be better, if you include the package directly in your project. Maybe you should try to find out, if the file exists for your studio(https://msdn.microsoft.com/en-us//library/system.io.file.exists(v=vs.110).aspx). (example from the page)

string curFile = @"c:\temp\test.txt";
Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist.");

Maybe this link also helps, to check your (studio)acces rights: Checking file/folder access permission

Upvotes: 0

Mough
Mough

Reputation: 56

It may be an issue with your package versioning. Try this solution presented for someone with a similar error.

Upvotes: 3

Related Questions