PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.71k stars 491 forks source link

Issue running cmdltes from MicrosoftPowerBIMgmt Module #2397

Closed olyamusok closed 4 years ago

olyamusok commented 4 years ago

System Details

System Details Output

### VSCode version: 1.41.1 26076a4de974ead31f97692a0d32f90d735645c0 x64

### VSCode extensions:
ms-vscode.powershell@2019.12.0

### PSES version:

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      5.1.14393.3383
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.3383
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

I am experiencing a problem with running cmdlets from MicrosoftPowerBIMgmt module. Same script works as expected in ISE but fails in Visual Studio Code. I am unable to run Get-PowerBIActivityEvent I believe the issue could be caused by version of the Newtonsoft.Json.dll that came with December version of the Powershell extension - it is 11.0.0 while the module requires 12.0.2 and higher

PS C:\Windows\system32> [Newtonsoft.Json.JsonConvert].Module

MDStreamVersion    : 131072
FullyQualifiedName : C:\Users\****\.vscode\extensions\ms-vscode.powershell-2019.12.0\modules\PowerShellEditorServices\bin\Desktop\Newtonsoft.Json.dll
ModuleVersionId    : 07e38931-19a9-45b2-9a35-e81930b1c8ad
MetadataToken      : 1
ScopeName          : Newtonsoft.Json.dll
Name               : Newtonsoft.Json.dll
Assembly           : Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
CustomAttributes   : {}
ModuleHandle       : System.ModuleHandle`

Expected Behaviour

execution the same cmdlet in ISE returns results as expected with no errors.

Actual Behaviour

I get the following error:

Get-PowerBIActivityEvent : Attempted to access an element as a type incompatible with the array.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...BIActivityEvent:GetPowerBIActivityEvent) [Get-PowerBIActivityEvent], ArrayTypeMismatchException
    + FullyQualifiedErrorId : Attempted to access an element as a type incompatible with the array.,Microsoft.PowerBI.Commands.Admin.GetPowerBIActivityEvent
rjmholt commented 4 years ago

@olyamusok this issue should be fixed in the latest powershell-preview extension. Could you uninstall the powershell extension, install powershell-preview and see if that resolves the issue?

olyamusok commented 4 years ago

@rjmholt I uninstalled powershell extensions and installed powershell-preview. The error is gone and the script runs, but output is missing all values for key-value pairs.

I get an empty shell like this for each activity while the output I get from running same code in ISE is just fine:

[
  {
    "Id": [],
    "RecordType": [],
    "CreationTime": [],
    "Operation": [],
    "OrganizationId": [],
    "UserType": [],
    "UserKey": [],
    "Workload": [],
    "UserId": [],
    "ClientIP": [],
    "UserAgent": [],
    "Activity": [],
    "ItemName": [],
    "WorkSpaceName": [],
    "DatasetName": [],
    "WorkspaceId": [],
    "ObjectId": [],
    "DatasetId": [],
    "DataConnectivityMode": [],
    "IsSuccess": [],
    "RequestId": [],
    "ActivityId": [],
    "TableName": []
  },
  {
    "Id": [],
    "RecordType": [],
    "CreationTime": [],
    "Operation": [],
    "OrganizationId": [],
    "UserType": [],
    "UserKey": [],
    "Workload": [],
    "UserId": [],
    "ClientIP": [],
    "UserAgent": [],
    "Activity": [],
    "ItemName": [],
    "WorkSpaceName": [],
    "DatasetName": [],
    "ReportName": [],
    "WorkspaceId": [],
    "ObjectId": [],
    "DatasetId": [],
    "ReportId": [],
    "IsSuccess": [],
    "ReportType": [],
    "RequestId": [],
    "ActivityId": [],
    "DistributionMethod": []
  },

here is NewtonSoft module I see for powershell-preview

> PS C:\windows\system32> [Newtonsoft.Json.JsonConvert].Module

MDStreamVersion    : 131072
FullyQualifiedName : C:\Users\***\.vscode\extensions\ms-vscode.powershell-preview-2019.12.0\modules\PowerShellEditorServices\bin\Common\Newtonsoft.Json.dll
ModuleVersionId    : d32db49e-5e34-4072-9da3-1845c03ddc3a
MetadataToken      : 1
ScopeName          : Newtonsoft.Json.dll
Name               : Newtonsoft.Json.dll
Assembly           : Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
CustomAttributes   : {}
ModuleHandle       : System.ModuleHandle
rjmholt commented 4 years ago

Thanks for trying that out! I now have a similar repro (I'm not familiar with the MicrosoftPowerBIMgmt module and don't have any PowerBI workspaces, but have hit an error earlier on that I think has the same root cause).

The PowerShell extension has a hard dependency on Newtonsoft.Json (as does PSScriptAnalyzer). Since PowerShell 6+ also ships with Newtonsoft.Json, we version to that.

After taking on new dependencies when rearchitecting the PowerShell extension, we did some work to isolate those dependencies when possible. It seems that the .NET Framework side of that work didn't solve the problem. However, experimenting with different solutions suggests that the problem may not be solvable in .NET Framework.

We have, however, solved the problem in .NET Core. I tried this in PowerShell 6 and 7 and it seems to work normally in those.

rjmholt commented 4 years ago

I'll continue playing with the .NET Framework solution to see if there's a possible solution, but I'm not optimistic.

olyamusok commented 4 years ago

@rjmholt thank you for looking into this in any case! I will keep this open for a bit longer in case something new will come up and will close in a month or so if not. Also can confirm that the code and cmdlets work just fine in VS code with PowerShell-preview after I also installed PowerShell 7 preview on that same machine.

SydneyhSmith commented 4 years ago

Closing as PS7 is now GA

rjmholt commented 4 years ago

@olyamusok can you try out this extension package for me and see if the issue persists?

psvsix.zip

It's a zip file, since GitHub won't allow uploading a VSIX directly. To install it, do this:

# Download psvsix.zip to current directory

# Extract zip
Expand-Archive ./psvsix.zip ./psvsix

# Install to VSCode
code --install-extension ./psvsix/PowerShell-Insiders.vsix

# Open VSCode
# Ensure the PowerShell Preview is installed and the PowerShell extension is disabled
# Close and reopen VSCode
# Try your repro steps
soulwiper commented 4 years ago

I don't have PowerShell-Insiders (I don't think). Is that going to be a problem? How do I tell if I have PowerShell-Insiders?

rjmholt commented 4 years ago

That VSIX linked above will install “PowerShell Insiders” rather than “PowerShell”. It will appear as a separate VSCode extension. So after you install that VSIX you need to uninstall or disable the “PowerShell” extension and restart VSCode. Then “PowerShell Insiders” will start up

TylerLeonhardt commented 4 years ago

This does not install PowerShell itself. We're only talking about the PowerShell extension and PowerShell Preview extension. You don't need to install anything else other than that VSIX

rjmholt commented 4 years ago

This does not install PowerShell itself.

Oh wow, rereading my comment I totally see the confusion. Yeah this installs the PowerShell extension for VSCode, not PowerShell the program. It will use the normal powershell.exe.

soulwiper commented 4 years ago

Yeah ok,  thank you both.  I am hoping to try it a little later today.  I will let you know.

Sent from my T-Mobile 4G LTE Device

Using Outlook for Android

On Tue, Mar 10, 2020 at 11:43 AM -0500, "Robert Holt" notifications@github.com wrote:

This does not install PowerShell itself.

Oh wow, rereading my comment I totally see the confusion. Yeah this installs the PowerShell extension for VSCode, not PowerShell the program. It will use the normal powershell.exe.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

soulwiper commented 4 years ago

Even with the preview (psvsix.zip) you requested me to try out I still run into the same problem as before. I can not debug and language issue prompt poping up.

However I did not an error poping up for a second on the terminal before and with the preview. I did not think of capturing it. I have attached it as an jpeg image below.

PowerShell preview extention error messages before blank terminal (with diagnostic)

and the log output: 3/10/2020 9:35:55 PM [NORMAL] - Visual Studio Code v1.42.1 64-bit 3/10/2020 9:35:55 PM [NORMAL] - PowerShell Extension v2020.3.0 3/10/2020 9:35:55 PM [NORMAL] - Operating System: Windows 64-bit 3/10/2020 9:35:55 PM [NORMAL] - Language server starting -- 3/10/2020 9:35:55 PM [NORMAL] - PowerShell executable: C:\Users\czachariou.dotnet\tools\pwsh.exe 3/10/2020 9:35:55 PM [NORMAL] - PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-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\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\logs\1583894155-02660d03-e13b-43f8-8e43-c76d363230961583894154248\EditorServices.log' -SessionDetailsPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\sessions\PSES-VSCode-13904-355584' -FeatureFlags @() 3/10/2020 9:35:55 PM [NORMAL] - PowerShell Editor Services args: Import-Module 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-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\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\logs\1583894155-02660d03-e13b-43f8-8e43-c76d363230961583894154248\EditorServices.log' -SessionDetailsPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\sessions\PSES-VSCode-13904-355584' -FeatureFlags @() 3/10/2020 9:35:55 PM [NORMAL] - pwsh.exe started. 3/10/2020 9:35:55 PM [NORMAL] - Waiting for session file 3/10/2020 9:37:56 PM [NORMAL] - Error occurred retrieving session file: Timed out waiting for session file to appear. 3/10/2020 9:37:56 PM [NORMAL] - Language server startup failed. 3/10/2020 9:37:56 PM [ERROR] - The language service could not be started: 3/10/2020 9:37:56 PM [ERROR] - Timed out waiting for session file to appear. 3/10/2020 9:42:52 PM [NORMAL] - Shutting down language client... 3/10/2020 9:42:52 PM [NORMAL] - Language server starting -- 3/10/2020 9:42:52 PM [NORMAL] - PowerShell executable: C:\Users\czachariou.dotnet\tools\pwsh.exe 3/10/2020 9:42:52 PM [NORMAL] - PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-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\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Diagnostic' -LogPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\logs\1583894572-02660d03-e13b-43f8-8e43-c76d363230961583894154248\EditorServices.log' -SessionDetailsPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\sessions\PSES-VSCode-13904-903383' -FeatureFlags @() 3/10/2020 9:42:52 PM [NORMAL] - PowerShell Editor Services args: Import-Module 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-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\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Diagnostic' -LogPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\logs\1583894572-02660d03-e13b-43f8-8e43-c76d363230961583894154248\EditorServices.log' -SessionDetailsPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\sessions\PSES-VSCode-13904-903383' -FeatureFlags @() 3/10/2020 9:42:52 PM [NORMAL] - pwsh.exe started. 3/10/2020 9:42:52 PM [NORMAL] - Waiting for session file 3/10/2020 9:43:11 PM [NORMAL] - Shutting down language client... 3/10/2020 9:43:11 PM [NORMAL] - Terminating PowerShell process... 3/10/2020 9:43:11 PM [NORMAL] - Language server starting -- 3/10/2020 9:43:11 PM [NORMAL] - PowerShell executable: C:\Users\czachariou.dotnet\tools\pwsh.exe 3/10/2020 9:43:11 PM [NORMAL] - PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-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\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\logs\1583894591-02660d03-e13b-43f8-8e43-c76d363230961583894154248\EditorServices.log' -SessionDetailsPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\sessions\PSES-VSCode-13904-295959' -FeatureFlags @() 3/10/2020 9:43:11 PM [NORMAL] - PowerShell Editor Services args: Import-Module 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-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\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Normal' -LogPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\logs\1583894591-02660d03-e13b-43f8-8e43-c76d363230961583894154248\EditorServices.log' -SessionDetailsPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\sessions\PSES-VSCode-13904-295959' -FeatureFlags @() 3/10/2020 9:43:11 PM [NORMAL] - pwsh.exe started. 3/10/2020 9:43:11 PM [NORMAL] - Waiting for session file 3/10/2020 9:44:52 PM [NORMAL] - Error occurred retrieving session file: Timed out waiting for session file to appear. 3/10/2020 9:44:52 PM [NORMAL] - Language server startup failed. 3/10/2020 9:44:52 PM [ERROR] - The language service could not be started: 3/10/2020 9:44:52 PM [ERROR] - Timed out waiting for session file to appear. 3/10/2020 9:45:12 PM [NORMAL] - Error occurred retrieving session file: Timed out waiting for session file to appear. 3/10/2020 9:45:12 PM [NORMAL] - Language server startup failed. 3/10/2020 9:45:12 PM [ERROR] - The language service could not be started: 3/10/2020 9:45:12 PM [ERROR] - Timed out waiting for session file to appear. 3/10/2020 9:45:16 PM [NORMAL] - Shutting down language client... 3/10/2020 9:45:16 PM [NORMAL] - Language server starting -- 3/10/2020 9:45:16 PM [NORMAL] - PowerShell executable: C:\Users\czachariou.dotnet\tools\pwsh.exe 3/10/2020 9:45:16 PM [NORMAL] - PowerShell args: -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Import-Module 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-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\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Diagnostic' -LogPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\logs\1583894716-02660d03-e13b-43f8-8e43-c76d363230961583894154248\EditorServices.log' -SessionDetailsPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\sessions\PSES-VSCode-13904-869624' -FeatureFlags @() 3/10/2020 9:45:16 PM [NORMAL] - PowerShell Editor Services args: Import-Module 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-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\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\modules' -EnableConsoleRepl -LogLevel 'Diagnostic' -LogPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\logs\1583894716-02660d03-e13b-43f8-8e43-c76d363230961583894154248\EditorServices.log' -SessionDetailsPath 'c:\Users\czachariou.vscode\extensions\ms-vscode.powershell-preview-2020.3.0\sessions\PSES-VSCode-13904-869624' -FeatureFlags @() 3/10/2020 9:45:16 PM [NORMAL] - pwsh.exe started. 3/10/2020 9:45:16 PM [NORMAL] - Waiting for session file 3/10/2020 9:47:16 PM [NORMAL] - Error occurred retrieving session file: Timed out waiting for session file to appear. 3/10/2020 9:47:16 PM [NORMAL] - Language server startup failed. 3/10/2020 9:47:16 PM [ERROR] - The language service could not be started: 3/10/2020 9:47:16 PM [ERROR] - Timed out waiting for session file to appear.

olyamusok commented 4 years ago

@rjmholt apologies for delayed response, just saw the tag. Glad @soulwiper was able to test.

soulwiper commented 4 years ago

@TylerLeonhardt and @rjmholt and @olyamusok is there a solution found to the dilemma of not been able to debug and the language issue when using PowerShell Extention 2020.3.0?

rjmholt commented 4 years ago

@olyamusok I believe @soulwiper is experiencing a different issue, which it turns out isn't fixed by this. We're going to try a fix for your issue in the next preview release

TylerLeonhardt commented 4 years ago

Can you all give the PowerShell Preview extension a try? We just did a release of it.

Don't forget to disable the regular PowerShell extension for VS Code when you enable the PowerShell Preview extension for VS Code

sqlchick commented 4 years ago

Thank you, thank you, thank you @olyamusok for commenting about installation of PowerShell 7 -- I also was getting blank [ ] results in VSCode when running Get-PowerBIActivityEvent, while getting results returned just fine from the ISE. At this time, version 7.0.2 (https://github.com/PowerShell/PowerShell/releases) is the latest & whatever it installed resolved the issue. (And just for completeness on this thread...the Powershell preview extension in VSCode also had no effect for me on this particular issue that I was facing.)