1

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?

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

The comma did it! Thanks very much for all your help!
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?
The only differences should be: use / as the path separator and do not double it (though doing so should actually be benign).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.