0

I am running my solution locally, trying to read a .json file location stored in the Web.config file, that resides to a location on a test server.

Web.config:

<add key="TokenFilePath" value="\\test\inetpub\wwwroot\meetings\token.json"/> 

This is the line where I get the error:

 var token = JObject.Parse(System.IO.File.ReadAllText(ConfigurationManager.AppSettings["TokenFilePath"]));

Exception:

Exception Details: Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Path '', line 0, position 0.

If I change the location of the token.json file to a location in the network like below, then I am able to read the file.

\\data\applications\meetings\credentials\token.json

Is this an issue of permissions? or is this an issue of reading a json file from a location in inetpub requires a different method?

Any help is appreciated to better understand this.

Thank you, Erasmo

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
erasmo carlos
  • 664
  • 5
  • 16
  • 37
  • Is this full exception? – Guru Stron May 18 '23 at 23:25
  • What does the string returned by `System.IO.File.ReadAllText(ConfigurationManager.AppSettings["TokenFilePath"])` look like? Is it an empty string? – dbc May 19 '23 at 00:34
  • @dbc, yes it is an empty string. – erasmo carlos May 19 '23 at 03:09
  • 1
    Well that's the problem. An empty string isn't well-formed JSON, see [What is the minimum valid JSON?](https://stackoverflow.com/q/18419428). Json.NET will throw an exception if you try to parse an empty string (or any other malformed JSON) into a `JObject`. – dbc May 19 '23 at 03:20

0 Answers0