[英]Error on dotnet watch run in Windows
我在運行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"
}
}
}
Startup.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();
}
任何建議從哪里開始尋找?
我懷疑文件為空,或者文件開頭為UTF-8 BOM。
線索在這里:
Error on line number '0': ''. -
它抱怨的東西是看不見的: ''
因此,可能是找不到預期的東西,或者是某種看不見的字符,其中包括BOM的'\'
。
由於精神錯亂,即使該代碼點可以出現在文件中的其他任何位置,也明確禁止JSON文件從一開始就使用BOM。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.