PowerShellEditorServices: PowerShell Extension v2020.3.0 breaks with AppLocker

We are allowing scripts and executables in the extension folder to be run in %OSDRIVE%\USERS\%USER%\.VSCODE\EXTENSIONS. The below error happens with the new version, but this does work with the previous version. As a workaround we have reverted back to the previous version for now.

Exception encountered starting EditorServices. Exception logged in D:\a\1\s\src\PowerShellEditorServices.Hosting\Commands\StartEditorServicesCommand.cs on line 247 in EndProcessing:
System.Management.Automation.CmdletInvocationException: Cannot dot-source this command because it was defined in a different language mode. To invoke this command without importing its contents, omit the '.' operator. ---> System.NotSupportedException: Cannot dot-source this command because it was defined in a different language mode. To invoke this command without importing its contents, omit the '.' operator.
   --- Slut på stackspårning för interna undantag ---
   vid System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   vid System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   vid System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   vid System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   vid System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   vid Microsoft.PowerShell.EditorServices.Hosting.EditorServicesLoader.LogPowerShellDetails()
   vid Microsoft.PowerShell.EditorServices.Hosting.EditorServicesLoader.LogHostInformation()
   vid Microsoft.PowerShell.EditorServices.Hosting.EditorServicesLoader.LoadAndRunEditorServicesAsync()
   vid Microsoft.PowerShell.EditorServices.Commands.StartEditorServicesCommand.EndProcessing()
2020-03-06 10:31:05 [NORMAL] - Visual Studio Code v1.42.1 64-bit
2020-03-06 10:31:05 [NORMAL] - PowerShell Extension v2020.3.0
2020-03-06 10:31:05 [NORMAL] - Operating System: Windows 64-bit
2020-03-06 10:31:05 [NORMAL] - Language server starting --
2020-03-06 10:31:05 [NORMAL] -     PowerShell executable: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
2020-03-06 10:31:05 [NORMAL] -     PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module 'c:\Users\johlju\.vscode\extensions\ms-vscode.powershell-2020.3.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2020.3.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\johlju\.vscode\extensions\ms-vscode.powershell-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'c:\Users\johlju\.vscode\extensions\ms-vscode.powershell-2020.3.0\logs\1583487065-bd4cd06b-756f-42c5-b413-6b485a2b237b1583487062238\EditorServices.log' -SessionDetailsPath 'c:\Users\johlju\.vscode\extensions\ms-vscode.powershell-2020.3.0\sessions\PSES-VSCode-13336-569282' -FeatureFlags @() 
2020-03-06 10:31:05 [NORMAL] -     PowerShell Editor Services args: Import-Module 'c:\Users\johlju\.vscode\extensions\ms-vscode.powershell-2020.3.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2020.3.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\johlju\.vscode\extensions\ms-vscode.powershell-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'c:\Users\johlju\.vscode\extensions\ms-vscode.powershell-2020.3.0\logs\1583487065-bd4cd06b-756f-42c5-b413-6b485a2b237b1583487062238\EditorServices.log' -SessionDetailsPath 'c:\Users\johlju\.vscode\extensions\ms-vscode.powershell-2020.3.0\sessions\PSES-VSCode-13336-569282' -FeatureFlags @() 
2020-03-06 10:31:05 [NORMAL] - powershell.exe started.
2020-03-06 10:31:05 [NORMAL] - Waiting for session file
2020-03-06 10:33:05 [NORMAL] - Error occurred retrieving session file
2020-03-06 10:33:05 [NORMAL] - Language server startup failed.
2020-03-06 10:33:05 [ERROR] - The language service could not be started: 
2020-03-06 10:33:05 [ERROR] - Timed out waiting for session file to appear.

If you need more debug information let us know.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 31 (10 by maintainers)

Most upvoted comments

Can you give this a go in the PowerShell Preview extension? A fix just went out with support for ConstrainedLanguage mode.

No, we currently don’t support signed script blocks, so any inline script is considered untrusted and will run in ConstrainedLanguage mode if AppLocker is enforcing system lock down.

@TylerLeonhardt I will get back to you regarding the ISE tomorrow, been a busy week.

I have I PR in that I think will help… I’ll be doing another release next week of PowerShell Preview.

For now, if you want to rebind F5 to workbench.action.terminal.runActiveFile that should work for you.

This is also called “Run Active File in Active Terminal” in the command pallet.

Just to get you folks unblocked here are some steps on how to rollback to the last version: https://docs.microsoft.com/en-us/powershell/scripting/components/vscode/using-vscode?view=powershell-7#using-an-older-version-of-the-powershell-extension-for-windows-powershell-v3-and-v4

We want to do more work here to support Constrained Language Mode which will allow us to support App Locker as well. Apologies for this interruption in your dev process and thanks for your understanding!