首页 > 解决方案 > 如何摆脱错误“无效的 appsettings.json 文件?

问题描述

如果我启动我的程序,我会收到如下错误:“ Invalid appsettings.json 文件

我需要这个文件来访问 Graph API。

如果我写了这个文件的本地目录,它就可以工作。

代码如下:

var config = new ConfigurationBuilder()
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.Build();


appsettings.json:
{
  "tenantId": "",
  "applicationId": "",
  "applicationSecret": "",
  "redirectUri": "https://localhost" 
}

标签: c#jsongraph

解决方案


I just ran the output of the CurrentDirectory and it was a wrong folder. Then I wrote a little Replace Code that replaced the wrong folder with the right one.


推荐阅读