2013-07-10 43 views
4

我試圖從命令行運行EF的migrate.exe作爲我們的構建過程的一部分。這是我的實際命令:對於EF6,Migrate.exe上導致TypeLoadException的原因是什麼?

migrate.exe Hydrogen.Data.dll /startupConfigurationFile:..\..\..\Hydrogen.Web\Web.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, Object[] parameters, 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:\code\Hydrogen\Hydrogen.Data\HydrogenData.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, Boolean skipCheckThis, Boolean fillCache, 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數據庫上。

回答

4

我今天剛碰到這個。運行migrate.exe時,如果使用了錯誤的DLL集,就會發生這種情況。

在我的情況,我以前在migrate.exe的.NET 4.5的版本,但使用編譯.NET 4.0的版本,我的項目。

更改DLL後,問題就消失了。

+0

你改變你的項目目標.NET 4.5解決這個問題,還是你告訴migrate.exe在哪裏可以找到.NET 4.0的DLL。如果你以後做了,你能告訴你是怎麼做到的嗎? – gabe

+0

@gabe如果你看看{path} \ tools \,它應該包含沒有EntityFramework.dll的migrate.exe。如果您嘗試運行migrate.exe,它應該抱怨缺少的DLL。我所做的只是將{path} \ lib \ net40 \ EntityFramework.dll複製到{path} \ tools \。不需要特殊的目標。 –

相關問題