ConfigurationBuilder构造函数中的System.IO.FileNotFoundException

时间:2019-07-09 13:37:53

标签: c# .net-core

我正在尝试在.net核心控制台应用程序中添加ConfigurationBuilder 运行以下代码时出现此异常。 我检查并在Directory.GetCurrentDirectory()中找到文件appsettings.json。

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not load file or assembly 'Microsoft.Extensions.FileProviders.Physical, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
  Source=Microsoft.Extensions.Configuration.FileExtensions
  StackTrace:
   at Microsoft.Extensions.Configuration.FileConfigurationExtensions.SetBasePath(IConfigurationBuilder builder, String basePath)
   at DashboardService.Program.Main(String[] args)
var builder = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json");

1 个答案:

答案 0 :(得分:0)

您将不得不将Microsoft.Extensions.FileProviders.Physical添加到您的项目中。 https://www.nuget.org/packages/microsoft.extensions.fileproviders.physical/ 在这里你可以接受。 希望对您有帮助