SolvedHome Invoke must be called on a background thread

Sometimes it works but almost everytime I'm getting error "Invoke must be called on a background thread." when using Package Manager Console to use migrations, other commands are affected too. After this error I can't run other commands at Package manager console

Package Manager Console

VS 15.2 (26430.12) Enterprise

Windows 10 1703 15063.332

Steps to reproduce:

1.Open VS2017

2.Open Package Manager Console

3.enable-migrations/add-migration/update-database... it gives error "Invoke must be called on a background thread."
after this given error, every command I try returns that the term is not reconized.

19 Answers

✔️Accepted Answer

The error is generated by NuGet attempting to execute init.ps1 scripts for packages installed in a project. It happens when user tries to invoke a command in PMC after pressing Enter. I noticed the problem occurred more often in earlier builds of Visual Studio.

Possible workaround would be opening a project with PMC window closed. You'll have to start a new instance of Visual Studio. Also make sure PMC window is closed before closing Visual Studio thus new instance will remember last window layout. In this scenario init.ps1 scripts will be executed correctly when PMC window is opened for the first time in current Visual Studio session.

Will work on figuring right fix to be shipped with next Visual Studio 2017 release.