加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – 导致EF6的Migrate.exe出现TypeLoadException的原

发布时间:2020-12-12 16:22:23 所属栏目:MsSql教程 来源:网络整理
导读:我正在尝试从命令行运行EF的migrate.exe作为构建过程的一部分.这是我的实际命令: migrate.exe Hydrogen.Data.dll /startupConfigurationFile:......Hydrogen.WebWeb.config /verbose 它不断抛出这个例外: System.Reflection.TargetInvocationException:
我正在尝试从命令行运行EF的migrate.exe作为构建过程的一部分.这是我的实际命令:
migrate.exe Hydrogen.Data.dll /startupConfigurationFile:......Hydrogen.WebWeb.config 
/verbose

它不断抛出这个例外:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.SqlServer.SqlProviderServices' threw an exception. ---> System.TypeLoadException: Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' from assembly 'EntityFramework.SqlServer,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089' does not have an implementation.
   at System.Data.Entity.SqlServer.SqlProviderServices..ctor()
   at System.Data.Entity.SqlServer.SqlProviderServices..cctor()
   --- End of inner exception stack trace ---
   at System.Data.Entity.SqlServer.SqlProviderServices.get_Instance()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target,Object[] arguments,Signature sig,Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object[] parameters,Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj,Object[] index)
   at System.Data.Entity.Config.ProviderServicesFactory.GetInstance(Type providerType)
   at System.Data.Entity.Internal.AppConfig.<.ctor>b__2(ProviderElement e)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at System.Data.Entity.Internal.AppConfig.<.ctor>b__1()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Data.Entity.Internal.AppConfig.get_DbProviderServices()
   at System.Data.Entity.Config.AppConfigDependencyResolver.RegisterDbProviderServices()
   at System.Data.Entity.Config.AppConfigDependencyResolver.GetServiceFactory(Type type,String name)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key,Func`2 valueFactory)
   at System.Data.Entity.Config.AppConfigDependencyResolver.GetService(Type type,Object key)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source,Func`2 predicate)
   at System.Data.Entity.Config.CompositeResolver`2.GetService(Type type,Object key)
   at System.Data.Entity.Config.IDbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver,Object key)
   at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection,DbCompiledModel model)
   at Hydrogen.Data.HydrogenData..ctor() in c:codeHydrogenHydrogen.DataHydrogenData.cs:line 18
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type,Boolean publicOnly,Boolean noCheck,Boolean& canBeCached,RuntimeMethodHandleInternal& ctor,Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,Boolean skipCheckThis,Boolean fillCache,StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly,StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type,Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at System.Data.Entity.Infrastructure.DbContextInfo.<CreateActivator>b__2()
   at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType,DbProviderInfo modelProviderInfo,AppConfig config,DbConnectionInfo connectionInfo)
   at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType,DbConnectionInfo connectionInfo)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration,DbContext usersContext)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Console.Program.Run()
   at System.Data.Entity.Migrations.Console.Program.Main(String[] args)
ERROR: Exception has been thrown by the target of an invocation.

当我从Visual Studio中运行Update-Database时,一切正常,所以我知道迁移本身正在工作.

这是在SQL Server数据库上.

解决方法

我今天刚遇到这个.当您运行migrate.exe时使用错误的DLL集时,可能会发生这种情况.

就我而言,我在migrate.exe中使用了.Net 4.5版本,但是使用.Net 4.0的版本编译了我的项目.

改变dll之后问题就消失了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读