2017-04-04 220 views
1

我首次將Entity Framework核心遷移到我的平均大小項目(大約100個表),現在我嘗試在包管理器控制檯中使用「Update-Database」調用對azure sql數據庫進行更改。EF核心遷移失敗:System.Runtime.Remoting.RemotingException:無法加載類型'Microsoft.EntityFrameworkCore.Design.IOperationResultHandler

我會得到這個錯誤總是: 異常消息: 堆棧跟蹤:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.Remoting.RemotingException: Cannot load type 'Microsoft.EntityFrameworkCore.Design.IOperationResultHandler, Microsoft.EntityFrameworkCore.Design, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. 

Server stack trace: 
at System.Runtime.Remoting.Messaging.MethodCall.ResolveMethod(Boolean bThrowIfNotResolved) 
at System.Runtime.Remoting.Messaging.MethodCall..ctor(SmuggledMethodCallMessage smuggledMsg, ArrayList deserializedArgs) 
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm) 
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatchCallback(Object[] args) 

Exception rethrown at [0]: 
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
at Microsoft.EntityFrameworkCore.Design.IOperationResultHandler.OnError(String type, String message, String stackTrace) 
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) 
--- End of inner exception stack trace --- 
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) 
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) 
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark) 
at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
at Microsoft.EntityFrameworkCore.Tools.AppDomainOperationExecutor.Execute(String operationName, Object resultHandler, IDictionary arguments) 
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3) 
at Microsoft.EntityFrameworkCore.Tools.OperationExecutorBase.InvokeOperationImpl(String operationName, IDictionary arguments) 
at Microsoft.EntityFrameworkCore.Tools.OperationExecutorBase.UpdateDatabase(String migration, String contextType) 
at Microsoft.EntityFrameworkCore.Tools.Commands.DatabaseUpdateCommand.Execute() 
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args) 
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args) 
Exception has been thrown by the target of an invocation. 

我的理解,它嘗試刪除該表的主鍵 - 之前存在多個類似的電話:

migrationBuilder.DropPrimaryKey(name: "pk_usr", table: "usr"); 

我的問題可能是我的原因 - 感謝您的幫助!

引用我有什麼有(均爲1.1.1.0):

Microsoft.EntityFrameworkCore 
Microsoft.EntityFrameworkCore.Design 
Microsoft.EntityFrameworkCore.Relational 
Microsoft.EntityFrameworkCore.Relational.Design 
Microsoft.EntityFrameworkCore.SqlServer 
Microsoft.EntityFrameworkCore.SqlServer.Design 

回答

0

檢查this能夠解決您的問題,如果不繼續下面的選項 EF Tools 1.1.0-preview4 Unrecognized option '--config' #7071

  1. 你試圖更新已經創建的數據庫?如果是這樣, 您的遷移可能與您的遷移數據庫 快照不同步。它以前沒有使用 遷移創建數據庫表和/或添加或刪除列或表而不使用 遷移,忘記使用您當前的遷移並創建新的 數據庫。
    1. 其他一些原因可能是您正在使用實體框架 class library,this doesn't currently work;
    2. 另一個原因可能使用一些包 當前未引用的是你的.Net核心運行時,由於可能的更新,所以一定要確保 您使用引用
    3. 或可能是,you updated your solution, or your solution used updated nuget packages that are not supported by the installed .NET Core Runtime. Ckeck that or the Vice versa包。
0

看起來你正在使用的Microsoft.EntityFrameworkCore.Tools不兼容的版本。確保你已經安裝了1.1.0版本。