Azure Function, EF Core, Can#39;t load ComponentModel.Annotations 4.2.0.0(Azure 函数,EF Core,无法加载 ComponentModel.Annotations 4.2.0.0)
问题描述
我创建了几个 .Net Standard 2.0 库,通过控制台应用程序测试了执行,以及几个测试 - 一切都很好.
I have created several .Net Standard 2.0 libraries, tested the execution via a console application, as well as several tests - all is good.
移动到 azure 函数,并得到以下运行时错误:
Move over to azure function, and get the following run-time error:
然后我尝试将该特定版本下载到 API Function 项目中:
I then try to download that specific version into the API Function project:
我正在使用 Visual Studio 15.7.0 预览版 5.0.我已将 Azure Function 更新到 4.7...,因为控制台和测试项目是 - 并且这些工作正常.
I'm using Visual Studio Version 15.7.0 Preview 5.0. I have updated the Azure Function to 4.7... as the console and test projects are - and those work.
已经在这个太多小时.. 所以我希望决议不是什么疯狂.Ef Core 2.1.0-rc1-final 也在其中.对Required、MaxLength、NotMapped 使用数据注解.
Been at this a far too many hours.. so I'm hoping the resolution isn't something crazy. Ef Core 2.1.0-rc1-final is also in the mix. Using data annotations for Required, MaxLength, NotMapped.
图形错误 说:Microsoft.EntityFrameworkCore:无法加载文件或程序集System.ComponentModel.Annotations,版本=4.2.0.0
Error in graphic says: Microsoft.EntityFrameworkCore: Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0
推荐答案
我建议在启动 Azure Function 后在下面运行此函数.它将任何程序集重定向到现有版本.
I would suggest running this function below once you start your Azure Function. It will redirect any assembly to an existing version.
public class FunctionsAssemblyResolver
{
public static void RedirectAssembly()
{
var list = AppDomain.CurrentDomain.GetAssemblies().OrderByDescending(a => a.FullName).Select(a => a.FullName).ToList();
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var requestedAssembly = new AssemblyName(args.Name);
Assembly assembly = null;
AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
try
{
assembly = Assembly.Load(requestedAssembly.Name);
}
catch (Exception ex)
{
}
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
return assembly;
}
}
这篇关于Azure 函数,EF Core,无法加载 ComponentModel.Annotations 4.2.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Azure 函数,EF Core,无法加载 ComponentModel.Annotations 4.2.0.0


- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01