Azure Function,EF Core,无法加载ComponentModel.Annotations 4.2.0.0 [英] Azure Function, EF Core, Can't load 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函数,就在下面运行此函数.它将所有程序集重定向到现有版本.
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 Function,EF Core,无法加载ComponentModel.Annotations 4.2.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!