Azure 函数,EF Core,无法加载 ComponentModel.Annotations 4.2.0.0

Azure Function, EF Core, Can#39;t load ComponentModel.Annotations 4.2.0.0(Azure 函数,EF Core,无法加载 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)