Could not parse the JSON file ,Error in Progam.cs asp.net core

后端 未结 11 1055
星月不相逢
星月不相逢 2021-02-07 19:42

I have some issues with the program.cs file, with the version of ASP.NetCORE 2.0

Here\'s my code

     public class Program
{
    public static void Main(st         


        
相关标签:
11条回答
  • 2021-02-07 20:15

    Just place ConnectionStrings in appsetting file then run the migration command.

    0 讨论(0)
  • 2021-02-07 20:19

    Check if you don't have any hidden spaces or tabs in your json. You can use https://jsonlint.com/ to verify your json format.

    0 讨论(0)
  • 2021-02-07 20:23

    I had a a similar problem as this in another thread and posted my solution over there: Application Startup Failure with Json read Error. Posting it here as well in case it disappears.


    I came across the same problem. In my case, I'd started implementing app secrets but left it halfway through. My secrets.json file was left linked but with invalid JSON.

    Check your .csproj to see if a <UserSecretId> property is set under <PropertyGroup>. If it's set, BuildWebHost() will look through your secrets.json file in '%APPDATA%\Microsoft\UserSecrets\{secretId}', in addition to your appsettings.json file. An error in either file will cause the method to fail, but it won't tell you which file it is.

    The solutions in my case were either to remove the <UserSecretId> property or

    0 讨论(0)
  • 2021-02-07 20:28

    Is your appSettings.json file (or whatever config you are using) formatted properly? WebHost.CreateDefaultBuilder will not be able to parse it correctly if there are invalid characters at the start. I saw this issue when a copy/paste added a space at the beginning of the file.

    0 讨论(0)
  • 2021-02-07 20:28

    There is a possibility it might happen when appsettings.json is not properly formated

    In my case, I had the below configuration and got the error

     {
    "ConnectionStrings": {
    "TransferDBConnection": 
     "Server=INGBTCPIC5DT04D;Database=TransferDB;Trusted_Connection=true;
     },
      ***{***
       "Logging": {
       "LogLevel": {
        "Default": "Warning"
       }
     },
     "AllowedHosts": "*"
    }
    

    ideally, it should be one extra { cause this problem

     {
     "ConnectionStrings": {
     "TransferDBConnection": 
     "Server=INGBTCPIC5DT04D;Database=TransferDB;Trusted_Connection=true;"
     },
      "Logging": {
      "LogLevel": {
        "Default": "Warning"
      }
    },
    "AllowedHosts": "*"
    }
    
    0 讨论(0)
  • 2021-02-07 20:32

    I had the same issue with one of my complex API's, sadly I've wasted few hours to find the issue.

    First of all check whether your appsettings.json is well formatted as a standard JSON.

    My issue was I've mistakenly typed some characters in the appsettings.json file like this, ( for me, 'ttings' characters cause this problem)

    Also check whether all your json files are not empty. A standard json should at least have two curly braces.

    0 讨论(0)
提交回复
热议问题