【问题标题】:Could not load type 'System.IO.Path' from assembly 'System.Runtime when deploying Azure function部署 Azure 函数时无法从程序集“System.Runtime”加载类型“System.IO.Path”
【发布时间】:2022-01-06 12:05:54
【问题描述】:

将函数部署到 Azure unsing dotnet 6 时出现以下错误:

Could not load type 'System.IO.Path' from assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

在我使用的启动脚本中:

.AddJsonFile(System.IO.Path.Combine(context.ApplicationRootPath, "appsettings.json"), optional: true, reloadOnChange: false)

获取appsettings.json的路径 有没有办法避免使用Path.Combine(我正在 windows 上测试并部署到 linux)或者是否有解决此错误的方法?

【问题讨论】:

  • .SetBasePath(context.FunctionAppDirectory).AddJsonFile("appsettings.json")
  • 这确实有效,尽管 FunctionAppDirectory 不可用,我选择了 ApplicationRootPath。不确定是否相关,但现在我收到一个新错误:Could not load file or assembly 'System.Net.Http, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  • 所以第二个问题没有直接关系(我使用的是废弃的包),您的解决方案解决了我发布的问题。谢谢!

标签: c# .net azure function


【解决方案1】:

通过以下方式,我实现了使用 appsettings.json 变量的任务:

ConfigurationBuilder
                    .SetBasePath(basePath)
                    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                    .AddJsonFile($"appsettings.{environmentName}.json", optional: true, reloadOnChange: true)
                    .AddEnvironmentVariables();

这与 CodeCaster 建议的类似,感谢他 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-08
    • 1970-01-01
    • 2017-04-19
    • 1970-01-01
    • 2016-01-02
    • 1970-01-01
    • 2018-10-13
    • 2018-11-29
    相关资源
    最近更新 更多