0

I'm trying to display a message box and have no problems in ISE/Powershell; however, when I run in Visual Studio Code I get this error:

Line |
  12 |  $user = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Method invocation failed because [Microsoft.VisualBasic.Interaction] does not contain a method named 'InputBox'.

I've added the Powershell extension to VS Code. It appears that I'm still missing something but I'm not sure what.

Any Ideas?

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
Mosby
  • 13
  • 1

1 Answers1

1

The implication is that your PowerShell extension (the PowerShell Integrated Console) uses a PowerShell [Core] version up to 7.0, which builds on .NET Core 3.1, where the [Microsoft.VisualBasic.Interaction]::InputBox() method isn't available, as Mathias R. Jessen points out.

In the upcoming PowerShell [Core] version 7.1, which builds on .NET 5, it will become available again.

Configure your PowerShell extension to use:

  • Either: Windows PowerShell, as preinstalled on any Windows machine.

    • Note that you'll then have to call Add-Type -AssemblyName Microsoft.VisualBasic before calling the method.
  • Or: For now, while PowerShell [Core] 7.1 isn't available yet, use the latest v7.1 preview version, available here, which builds on a .NET 5 preview where the method is already available.

See the bottom section of this answer for how to configure the PowerShell extension to use a specific PowerShell version.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    The comma did it! Thanks very much for all your help! – Mosby Aug 28 '20 at 20:46
  • One more question if you don't mind. I tried to duplicate this on my Mac (my actual preferred system) and I got it all setup to point to 7.1, etc. like you showed me on Windows. But I'm still getting the same error. Is there something different particular to the Mac? – Mosby Aug 28 '20 at 21:05
  • The only differences should be: use `/` as the path separator and do _not_ double it (though doing so should actually be benign). – mklement0 Aug 28 '20 at 21:13