【问题标题】:Azure Function: System.Private.CoreLib: Could not load file or assembly 'System.ComponentModel.Annotations...'Azure 函数:System.Private.CoreLib:无法加载文件或程序集“System.ComponentModel.Annotations...”
【发布时间】:2020-12-17 03:06:23
【问题描述】:

我有 .NET Standard 2.1 类库,其中包括一个对象模型,该对象模型具有使用 DataAnnotations 属性的属性。我正在从针对 .NET Core 3.1 的 v3 Azure 函数中使用它。我可以从 .NET Core 控制台应用程序中毫无问题地使用该库,但是当我从 Azure Function 应用程序中使用它时,我在运行时收到此错误:

System.Private.CoreLib: Exception while executing function: ... System.Private.CoreLib: Could not load file or assembly 'System.ComponentModel.Annotations, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

有趣的是,填充对象模型时我没有收到此错误,只有在尝试将其序列化为 JSON 时。

我也尝试将 System.ComponentModel.Annotations nuget 包添加到函数项目中,并尝试了针对类似问题的建议修复,例如 https://stackoverflow.com/a/44079161/892770https://stackoverflow.com/a/50776946/892770,但无济于事。

有什么想法吗?谢谢!

【问题讨论】:

    标签: c# azure .net-core azure-functions


    【解决方案1】:

    我收回了,第二个答案,Azure Function, EF Core, Can't load ComponentModel.Annotations 4.2.0.0,确实解决了我的问题。我在 CurrentDomain_AssemblyResolve 函数中的 Assembly.Load 上遇到异常,并认为我仍然失败,但看起来这是意料之中的。

    【讨论】:

      猜你喜欢
      • 2019-12-29
      • 2018-10-05
      • 1970-01-01
      • 2017-10-18
      • 2020-01-14
      • 2018-10-13
      • 2018-11-29
      • 1970-01-01
      • 2018-09-10
      相关资源
      最近更新 更多