2

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.

Jim Hewitt
  • 1,726
  • 4
  • 24
  • 26
Alan
  • 822
  • 1
  • 16
  • 39

2 Answers2

3

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

Community
  • 1
  • 1
Mough
  • 56
  • 4
  • Thanks for the link. That helped. Found the solution. My web.config file didn't have a reference to the newtonsoft.json package and my dll project was referencing a different version of the newtonsoft.json package. Once both projects were referencing the same version, everything worked. I don't understand why, however, they have to be the same version? – Alan Sep 17 '16 at 15:48
0

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

Community
  • 1
  • 1
Garamaru
  • 106
  • 1
  • 1
  • 11
  • The project does include the package directly. The dll library I created earlier also has a copy of the same package that it references. I inserted the code you provided and it does return File exists. – Alan Sep 17 '16 at 15:20