1

I am learning EntityFramework Core. I was just going perfect. I was adding migraitons and removing them but then I need to work on UI for some days then again I need to add some migration but it didn't work. I tried to add and remove(this I done many times) Microsoft.EntityFrameworkCore.Tools but it didn't work. What I get in package manager console when I add the command "add-migration someMigration" is below. I've been searching on it for almost 10 days on different sites but I couldn't understand what happened. Thanx in Advance.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: Method 'Clone' in type            'Microsoft.EntityFrameworkCore.Infrastructure.Internal.SqlServerOptionsExtension' from assembly        'Microsoft.EntityFrameworkCore.SqlServer, Version=1.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
   at      System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at   System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
   at   System.Reflection.RuntimeMethodInfo.GetParameters()
   at   System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)
   at   System.Exception.GetStackTrace(Boolean needFileInfo)
   at   System.Exception.ToString(Boolean needFileLineInfo, Boolean needMessage)
   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.AddMigration(String name, String outputDir, String contextType)
   at    Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsAddCommand.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.
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
zakria
  • 11
  • 5
  • System.Reflection.TargetInvocationException wraps another exception you need to check the inner exception for the specific error. Post the inner exception as well, because just this message doesn't say anything more than "An exception occurred while I tried to call a method using reflection" – Titian Cernicova-Dragomir Sep 11 '17 at 07:18
  • @TitianCernicova-Dragomir If you read the post carefully, you'll notice that the exception is not generated by OP code, but EF Core command run in PM console, hence there is nothing OP can do to further identify the problem (bug) in MSFT code. – Ivan Stoev Sep 11 '17 at 07:36
  • What EF Core version are you on? And is the installed `Microsoft.EntityFrameworkCore.Tools` version the same? – Ivan Stoev Sep 11 '17 at 07:59
  • @Ivan I am using EntityFrameworkCore 2.0.0-preview1-final, and EntityFrameworkCore.Tools 2.0.0-preview1-final, .Net Framework 4.6 – zakria Sep 11 '17 at 14:19
  • It is possible to have different versions of packages which could be incompatible due to breaking changes causing error in reflection. Can you upgrade all the ASP.NET core packages to 2.0 and try? – Smit Sep 11 '17 at 22:54
  • @Smit It gave another erorr like when i upgraded EFCore form 2.0.0-preview1-final to stable version 2.0.0 It gave the follwoing erorr Severity Code Description Project File Line Suppression State Error Could not install package 'Microsoft.EntityFrameworkCore 2.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. – zakria Sep 13 '17 at 16:11
  • @Ivan Sorry my internet was down, Both versions are same, what should i do – zakria Sep 13 '17 at 16:53
  • 1
    @zakria Np. I would suggest taking the Smit advice. However you'll need first to install Visual Studio 2017 Update 15.3.0. See https://stackoverflow.com/questions/45693662/can-not-upgrade-from-ef-core-1-1-2-to-version-2-0-0/45695187#45695187 – Ivan Stoev Sep 13 '17 at 16:58
  • @Ivan I have installed vs17 update 15.3.4 and tried to update 'Microsoft.EntityFrameworkCore' from 2.0.0preview1-final to 2.0.0 but it again gave the same error that i mentrioned earlier. What should I do now, Thnx fro being pateient – zakria Sep 14 '17 at 16:56
  • @zakria Np, I know it's nightmare :) Did you notice the other EFC2.0 requirement - targeting .NET Framework 4.6.1+? – Ivan Stoev Sep 14 '17 at 16:59
  • @Ivan You mean upgrading my project from 4.6 to 4.6.1 – zakria Sep 14 '17 at 17:19
  • indeed. Unfortunately. – Ivan Stoev Sep 14 '17 at 17:20
  • @IvanStoev I was reading about it – zakria Sep 14 '17 at 17:20

0 Answers0