在 Windows 中运行 dotnet watch 时出错

拉吉

我在运行 dotnet watch run 时遇到以下错误。

Unhandled Exception: System.FormatException: Could not parse the JSON file. 
Error on line number '0': ''. -
--> Newtonsoft.Json.JsonReaderException: Error reading JObject from 
JsonReader. Path '', line 0, position 0
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings 
settings)   at 

Microsoft.Extensions.Configuration.Json.JsonConfigurationFileParser.Parse(Stream input)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider.Load(Stream stream)
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at WebApplicationBasic.Startup..ctor(IHostingEnvironment env) in \Microservices\TestProject\Startup.cs:line 25

我确认没有任何错误的 json 文件。如果有帮助,请添加我的项目文件。这可能无关紧要,但我不确定在哪里看。

appsettings.json:

{
  "ASPNETCORE_ENVIRONMENT": "Development",
  "ConnectionStrings": {
    "Default": "Server=localhost; database=TestProject; Integrated Security=True"
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

启动.cs:

public Startup(IHostingEnvironment env)
{
    var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                .AddEnvironmentVariables();
     Configuration = builder.Build();
}

public IServiceProvider ConfigureServices(IServiceCollection services)
{
     // Add framework services.
     services.AddDbContext<TestDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("Default")));
     services.AddMvc();
     // services.AddMvcCore()
     // .AddApiExplorer();

     return services.BuildServiceProvider();
}

任何建议从哪里开始寻找?

Ben

我怀疑文件是空的,或者它以 UTF-8 BOM 开头。

线索在这里:

Error on line number '0': ''. -

它抱怨的东西是看不见的: ''

所以可能在预期的地方没有发现任何东西,或者它是某种不可见的特征,其中包括'\uFEFF'BOM。

出于精神错乱的原因,JSON 文件在开始时被明确禁止使用 BOM,即使该代码点可以出现在文件中的任何其他位置。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

从 Visual Studio 运行 dotnet watch run

对dotnet Framework 4.7.1运行强化扫描时出错

在Kubernetes上运行dotnet core 3.0 docker映像时出错

Lua:尝试在 Windows 中运行脚本时出错

在“ gulp watch”时出错

运行Docker for Windows,暴露端口时出错

尝试运行Windows Steam时出错

在 Windows 中右键单击运行 DotNet Core 项目

将主机目录安装为网络共享时,babel-watch无法从Windows主机上的docker容器中运行

dotnet运行还是通过命令行在开发环境中使用dotnet watch?

dotnet watch run命令中的取消路径无效

在Windows中托管WCF服务时出错

在virtualenv中安装Flask时出错-Windows

Python在Windows中读取目录时出错

在 Windows 10 中安装 kubectl 时出错

运行单元测试时,DotNet Core'CspParameters'仅需要Windows加密API(CAPI)

在 Windows 10 中安装的 ubuntu 中运行 sudo 命令时出错?

在Windows 7中的Docker上运行ASP.NET Core WebApp时出错(调试)

在Windows Task Scheduler中以cronjob运行批处理文件时出错

在项目 .net 6 使用层中执行 docker build 时 dotnet restore 出错

在 VS 15 中编译 .Net Core 1.0.4 项目时出错:缺少 Microsoft.DotNet.Props

从Windows Service应用程序运行Excel宏时出错

Ansible 在运行 Windows“dir”命令时出错?

从Windows窗体应用程序运行PowerShell脚本时出错

在Windows上运行npm命令时出错:graceful-fs

在 Windows 上运行 Kafka 服务器时出错

在Windows Server 2016中打开Windows Defender时出错

在Docker容器中还原dotnet期间出错

在dotnet构建期间生成代码时出错