Col*_*ppo 5 c# visual-studio asp.net-core-mvc visual-studio-code
我在尝试运行 ASP.Net Core 3.1 项目时遇到错误。该错误是在CreateHostBuilder
中Program.cs
public class Program {
public static void Main(string[] args) {
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
Run Code Online (Sandbox Code Playgroud)
尚未从 Visual Studio 2019 的默认 ASP.NET Core Web 应用程序模板编辑。它给出了例外
System.FormatException: '无法解析 JSON 文件。'
然而,它并没有准确地指代它无法解析的 JSON 文件。这是一个包含所有 3 个可以解析的现有 JSON 文件的pastebin。
这是完整的错误堆栈:
HResult=0x80131537
Message=Could not parse the JSON file.
Source=Microsoft.Extensions.Configuration.Json
StackTrace:
at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider.Load(Stream stream)
at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException(ExceptionDispatchInfo info)
at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
at Microsoft.Extensions.Hosting.HostBuilder.BuildAppConfiguration()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at <filename>.Main(String[] args) in <filename>:line 13
This exception was originally thrown at this call stack:
System.Text.Json.ThrowHelper.ThrowJsonReaderException(ref System.Text.Json.Utf8JsonReader, System.Text.Json.ExceptionResource, byte, System.ReadOnlySpan<byte>)
System.Text.Json.Utf8JsonReader.ReadSingleSegment()
System.Text.Json.Utf8JsonReader.Read()
System.Text.Json.JsonDocument.Parse(System.ReadOnlySpan<byte>, System.Text.Json.Utf8JsonReader, ref System.Text.Json.JsonDocument.MetadataDb, ref System.Text.Json.JsonDocument.StackRowStack)
System.Text.Json.JsonDocument.Parse(System.ReadOnlyMemory<byte>, System.Text.Json.JsonReaderOptions, byte[])
System.Text.Json.JsonDocument.Parse(System.ReadOnlyMemory<char>, System.Text.Json.JsonDocumentOptions)
System.Text.Json.JsonDocument.Parse(string, System.Text.Json.JsonDocumentOptions)
Microsoft.Extensions.Configuration.Json.JsonConfigurationFileParser.ParseStream(System.IO.Stream)
Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider.Load(System.IO.Stream)
Inner Exception 1:
JsonReaderException: '{' is an invalid start of a property name. Expected a '"'. LineNumber: 2 | BytePositionInLine: 4
Run Code Online (Sandbox Code Playgroud)
当我开始使用 VS Code 而不是我通常使用的 Visual Studio 时,它就开始了。但是,该项目可以在另一台只运行 Visual Studio 的Windows 机器上成功运行。我已经尝试了一些东西,但我没有想法。以下是我尝试过的步骤:
appsettings.json
,appsettings.Development.json
并且launchSettings.json
没有在此线程中解决的语法错误.csproj
args
值是大小为 [1] 的字符串数组。使用 [0] 位置并包含字符串%LAUNCHER_ARGS%
。环境变量未出现在app.config
Windows中或之内。我确认args
仍然与测试纯模板项目相同和功能。小智 8
听起来不像是破记录,但任何遇到此问题的人,请确保您的 appsettings.json 格式正确。
我发现在我的情况下,我的连接字符串中没有正确设置转义字符。我没有 .\\MSSQLSERVER,而是 .\MSSQLSERVER。
如果您在本地机器上有一个测试实例,请取出云的连接字符串并将其替换为本地机器的连接字符串(应该更简单),这应该会引导您走向正确的方向。
归档时间: |
|
查看次数: |
11088 次 |
最近记录: |