.net core System.TypeLoadException:无法加载类型';Microsoft.EntityFrameworkCore.Infrastructure.DesignTimeProviderServicesAttribute';

.net core System.TypeLoadException:无法加载类型';Microsoft.EntityFrameworkCore.Infrastructure.DesignTimeProviderServicesAttribute';,.net-core,entity-framework-core,.net-core-3.1,ef-core-3.1,.net Core,Entity Framework Core,.net Core 3.1,Ef Core 3.1,我已经使用.netcore3.1从现有数据库更新模型 尝试在package manager控制台中使用下面的注释添加实体 dotnet ef dbcontext scaffold "Server=xxxxxxxx;Database=Test;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer --output-dir UserEntity --table users 得到下面的异常 Build

我已经使用
.netcore3.1
从现有数据库更新模型

尝试在package manager控制台中使用下面的注释添加实体

dotnet ef dbcontext scaffold "Server=xxxxxxxx;Database=Test;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer --output-dir UserEntity --table users
得到下面的异常

Build started...
Build succeeded.
System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Infrastructure.DesignTimeProviderServicesAttribute' from assembly 'Microsoft.EntityFrameworkCore, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
   at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
   at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
   at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit)
   at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](Assembly element)
   at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureProviderServices(String provider, IServiceCollection services, Boolean throwOnError)
   at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Could not load type 'Microsoft.EntityFrameworkCore.Infrastructure.DesignTimeProviderServicesAttribute' from assembly 'Microsoft.EntityFrameworkCore, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
已开始生成。。。
构建成功。
System.TypeLoadException:无法从程序集“Microsoft.EntityFrameworkCore,Version=3.1.6.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”加载类型“Microsoft.EntityFrameworkCore.Infrastructure.DesignTimeProviderServicesAttribute”。
位于System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule模块、Int32 typeToken、RuntimeTypeHandle[]TypeInstanceContext、RuntimeTypeHandle[]MethodInstanceContext)
位于System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken,类型[]genericTypeArguments,类型[]genericMethodArguments)
在System.Reflection.CustomAttribute.FilterCustomAttribute记录处(MetadataToken caCtorToken、MetadataImport&scope、RuntimeModule decoratedModule、MetadataToken decoratedToken、RuntimeType attributeFilterType、Boolean mustBeInheritable、ListBuilder`1和derivedAttributes、RuntimeType和attributeType、IRontimeMethodInfo和ctor、Boolean和ctorHasParameters、Boolean和isVarArg)
在System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1&attributes,RuntimeModule decoratedModule,Int32 decoratedMetadataToken,RuntimeType attributeFilterType,Boolean mustBeInheritable,ListBuilder`1 derivedAttributes)
位于System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule、Int32 decoratedMetadataToken、Int32 pcaCount、RuntimeType attributeFilterType)
位于System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly程序集,RuntimeType caType)
位于System.Reflection.RuntimeAssembly.GetCustomAttributes(类型attributeType,布尔继承)
位于System.Attribute.GetCustomAttributes(汇编元素,类型attributeType,布尔继承)
位于System.Attribute.GetCustomAttribute(汇编元素,类型attributeType,布尔继承)
位于System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](汇编元素)
位于Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureProviderServices(字符串提供程序、IServiceCollection服务、布尔throwOnError)
位于Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(字符串提供程序)
位于Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(字符串提供程序、字符串连接字符串、字符串outputDir、字符串outputContextDir、字符串dbContextClassName、IEnumerable`1模式、IEnumerable`1表、布尔useDataAnnotations、布尔重写文件、布尔useDatabaseNames)
位于Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(字符串提供程序、字符串连接字符串、字符串输出目录、字符串输出目录ContextDir、字符串dbContextClassName、IEnumerable`1架构过滤器、IEnumerable`1表格过滤器、布尔useDataAnnotations、布尔重写文件、布尔useDatabaseNames)
在Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.c__DisplayClass0_0.b_0()中
在Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.c__DisplayClass3_0`1.b__0()中
位于Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(操作)
无法从程序集“Microsoft.EntityFrameworkCore,版本=3.1.6.0,区域性=中性,PublicKeyToken=adb9793829ddae60”加载类型“Microsoft.EntityFrameworkCore.Infrastructure.DesignTimeProviderServicesAttribute”。
注意:

使用以下实体版本

  • Microsoft.EntityFrameworkCore.Design-3.1.6
  • Microsoft.EntityFrameworkCore.SqlServer-1.1.6
  • 有人能帮我解决这个问题吗


    提前感谢。

    为什么要使用较旧版本的
    Microsoft.EntityFrameworkCore.SqlServer
    ?请尝试将其更新为
    Microsoft.EntityFrameworkCore.SqlServer 3.1.6

    当我搜索错误时,似乎只有在Microsoft.EntityFrameworkCore.Infrastructure下的Entity Framework Core 1.1之前才支持
    DesignTimeProviderServiceAttribute

    由于您使用的是较新版本的Microsoft.EntityFrameworkCore.Infrastructure不包括
    DesignTimeProviderServicesAttribute
    。请在此处的MSDN上验证相同内容