“rzc discover exited with code -2147450749” and “hostpolicy.dll required” errors

We have recently upgrade a .NET Core 2.2 application to 3.1 version. While trying to run it in Visual Studio, we came across “rzc discover exited” and “hostpolicy.dll required” errors:

  • In Visual Studio output while trying to run the solution: rzc discover exited with code -2147450749
  • In PowerShell after performing “build run” command: A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in [path]