Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with Get-PowerBIWorkspace #60

Closed
Rocca16 opened this issue Jul 25, 2018 · 31 comments

Comments

Projects
None yet
@Rocca16
Copy link

commented Jul 25, 2018

I'm getting an error "Attempted to access an element as a type incompatible with the array."

error

@shietpas

This comment has been minimized.

Copy link

commented Jul 27, 2018

I am getting this issue too. This also occurs for Get-PowerBIDataset and Get-PowerBIReport

@BrianPie

This comment has been minimized.

Copy link

commented Jul 30, 2018

I am also getting the same message for all 3 commands.
Get-PowerBIWorkspace : Attempted to access an element as a type incompatible with the array.
At line:1 char:15

  • $workspaces = Get-PowerBIWorkspace
  •           ~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : WriteError: (Microsoft.Power...owerBIWorkspace:GetPowerBIWorkspace) [Get-PowerBIWorkspace], ArrayTypeMismatchException
    • FullyQualifiedErrorId : Attempted to access an element as a type incompatible with the array.,Microsoft.PowerBI.Commands.Workspaces.GetPowerBIWorkspace
@CodeCyclone

This comment has been minimized.

Copy link
Collaborator

commented Jul 30, 2018

The issue is likely due to a mismatch in Newtonsoft.Json between the Power BI cmdlets and some other cmdlets loaded into PowerShell session (via profile or calling directly). You can verify by running powershell -noprofile and then call the cmdlets and see if you get the error.

Other workarounds include using PowerShell Core which the latest version of MicrosoftPowerBIMgmt supports or Azure Cloud Shell which be releasing with MicrosoftPowerBIMgmt automatically installed when you login.

@CodeCyclone

This comment has been minimized.

Copy link
Collaborator

commented Jul 30, 2018

Run Resolve-PowerBIError -Last to get more details of the error, then I can confirm the conflict

@CodeCyclone CodeCyclone self-assigned this Jul 30, 2018

@CodeCyclone CodeCyclone added the bug label Jul 30, 2018

@BrianPie

This comment has been minimized.

Copy link

commented Jul 30, 2018

@CodeCyclone

This comment has been minimized.

Copy link
Collaborator

commented Jul 30, 2018

Yep that is the Newtonsoft.Json conflict. Sadly PowerShell only uses one AppDomain per PowerShell session so once a type is loaded (by some other PowerShell module) it can't be replaced or unloaded by something else. We could look into removing Newtonsoft.Json usage but that is coming in due to Power BI SDK so its usage would have to be replaced as well.

@BrianPie

This comment has been minimized.

Copy link

commented Jul 30, 2018

@CodeCyclone

This comment has been minimized.

Copy link
Collaborator

commented Jul 30, 2018

Did you try a fresh PowerShell console, open up PowerShell with no profile:
In a Run window (Win+R): powershell -noprofile

Other option is using PowerShell Core - https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-powershell-core-on-windows?view=powershell-6

@Rocca16

This comment has been minimized.

Copy link
Author

commented Jul 30, 2018

@CodeCyclone

This comment has been minimized.

Copy link
Collaborator

commented Jul 30, 2018

Can you run the following:
get-module MicrosoftPowerBI* -ListAvailable

Call a Power BI cmdlet like: Get-PowerBIWorkspace

Then locate which Newtonsoft.Json assembly is being loaded by running:
[Newtonsoft.Json.JsonConvert].Module

@Rocca16

This comment has been minimized.

Copy link
Author

commented Jul 30, 2018

@CodeCyclone

This comment has been minimized.

Copy link
Collaborator

commented Jul 30, 2018

It looks like version 1.0.289 dropped the wrong version of Newtonsoft.Json, it should have been version 9.0.0 which I'm seeing on build 1.0.295 have. Can you try to upgrade the module:
Get-Module MicrosoftPowerBIMgmt* -ListAvailable | Uninstall-Module -Force
Install-Module MicrosoftPowerBIMgmt

@Rocca16

This comment has been minimized.

Copy link
Author

commented Jul 30, 2018

@CodeCyclone

This comment has been minimized.

Copy link
Collaborator

commented Jul 30, 2018

I assume it still errors with the new version? That assembly is coming from GAC, likely placed there by another product. If it is used by another product and it's expecting to be there, removing it would be bad and it would break that product.

PowerShell Core may work in this sceanrio as uses a different runtime and the GAC assembly likely isn't used here. Otherwise I will look into replacing the usage of it but that would be a couple of weeks out.

@Rocca16

This comment has been minimized.

Copy link
Author

commented Jul 30, 2018

@shietpas

This comment has been minimized.

Copy link

commented Jul 31, 2018

PowerShell Core worked for me, and the -noprofile option also worked in Windows PowerShell. I appreciate the assistance!

@hmayer1980

This comment has been minimized.

Copy link

commented Aug 1, 2018

I am having the same issue, but my Newtonsoft.Json.dll is Version=9.0.0.0,

PS C:\Users\hmayer> get-module MicrosoftPowerBI* -ListAvailable

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version Name ExportedCommands


Manifest 1.0.295 MicrosoftPowerBIMgmt
Binary 1.0.295 MicrosoftPowerBIMgmt.Data {Add-PowerBIDataset, New-PowerBIDataset, New-PowerBITable,...
Binary 1.0.295 MicrosoftPowerBIMgmt.Profile {Connect-PowerBIServiceAccount, Disconnect-PowerBIServiceA...
Binary 1.0.295 MicrosoftPowerBIMgmt.Reports {Get-PowerBIReport, Export-PowerBIReport, Get-PowerBIDashb...
Binary 1.0.295 MicrosoftPowerBIMgmt.Workspaces {Get-PowerBIWorkspace, Add-PowerBIWorkspaceUser, Remove-Po...

PS C:\Users\hmayer> Get-PowerBIWorkspace
Get-PowerBIWorkspace : Attempted to access an element as a type incompatible with the array.
At line:1 char:1

  • Get-PowerBIWorkspace
  •   + CategoryInfo          : WriteError: (Microsoft.Power...owerBIWorkspace:GetPowerBIWorkspace) [Get-PowerBIWorkspac
     e], ArrayTypeMismatchException
      + FullyQualifiedErrorId : Attempted to access an element as a type incompatible with the array.,Microsoft.PowerBI.
     Commands.Workspaces.GetPowerBIWorkspace
    
    

PS C:\Users\hmayer> [Newtonsoft.Json.JsonConvert].Module

MDStreamVersion : 131072
FullyQualifiedName : C:\Program Files\WindowsPowerShell\Modules\MicrosoftPowerBIMgmt.Profile\1.0.295\lib\netstandard2.0\Newtonsoft.Json.dll
ModuleVersionId : 5179dd1b-79f0-47d0-ac65-7ed8a725efc1
MetadataToken : 1
ScopeName : Newtonsoft.Json.dll
Name : Newtonsoft.Json.dll
Assembly : Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
CustomAttributes : {}
ModuleHandle : System.ModuleHandle

PS C:\Users\hmayer> [Newtonsoft.Json.JsonConvert].ModuleNewtonsoft.Json

@BrianPie

This comment has been minimized.

Copy link

commented Aug 7, 2018

Is there a solution or work around If the GAC has this version Newton.Json v4.0_7.0.0.0 ?

@CodeCyclone

This comment has been minimized.

Copy link
Collaborator

commented Aug 7, 2018

If PowerShell Core doesn't work, other option is to try https://shell.azure.com which has MicrosoftPowerBIMgmt preinstalled so you can call Login-PowerBI (follow instructions for login displayed in prompt) and then you can call the cmdlets. Note, shell.azure.com requires access to an Azure subscription due to it using a storage account.

We plan on replacing usage of the Power BI SDK which uses Newtonsoft.Json which will remove this dependency issue, I completely understand the frustration this issue causes and its magnified with how PowerShell works.

@BrianPie

This comment has been minimized.

Copy link

commented Aug 7, 2018

@mtakmddk

This comment has been minimized.

Copy link

commented Aug 30, 2018

I also experience this issue and I can reproduce the error with a clean powershell profile. All it takes is a script that first connects to Azure (eg. by using the Login-AzureRmAccount cmdlet from AzureRM.profile, part of the Azure module).

My script needs to connect to Azure to retrieve relevant group id's before using the Get-PowerBIWorkspace cmdlet, but doing so loads a different version of Newtonsoft.Json.dll than the one used by MicrosoftPowerBIMgmt.Profile.

Attached is a screenshot from processexplorer.exe showing the Newtonsoft.Json dll versions referenced by the powershell.exe process after running the script:
newtonsoft

@CodeCyclone CodeCyclone referenced this issue Sep 5, 2018

Merged

Merging Dev #78

CodeCyclone added a commit that referenced this issue Sep 5, 2018

Merge pull request #78 from Microsoft/dev
- Fixes netstandard issue commented on in issues #60, #63, #41 (note: this doesn't fix Newtonsoft.Json conflicts mentioned in #60 ArrayTypeMismatchException)

- Fix for issue #62 casting column objects by @kenakamu

- New Data cmdlets for Add-PowerBIDataset, Add-PowerBIRow, Get-PowerBITable, New-PowerBIColumn, New-PowerBITable, Remove-PowerBIRow, and Set-PowerBITable by @kenakamu

- General Doc fixes

- Internal improvements
@CodeCyclone

This comment has been minimized.

Copy link
Collaborator

commented Sep 6, 2018

Netstandard issue should be fixed in https://www.powershellgallery.com/packages/MicrosoftPowerBIMgmt/1.0.326.
This does not fix the ArrayTypeMismatchException from Newtonsoft.Json conflicts, that is something we are tracking to fix.

@titoSwin

This comment has been minimized.

Copy link

commented Nov 12, 2018

I have the same issue, but don't see any updates since September 5. None of the workarounds work for me. Is there any progress on this?

@reubster

This comment has been minimized.

Copy link

commented Nov 14, 2018

Powershell Core (6.1.1) works for me also.

@CodeCyclone

This comment has been minimized.

Copy link
Collaborator

commented Nov 27, 2018

1.0.326 fixed some of the issues but it can't fix the OSPlatform issue on some environments. @titoSwin did you try to upgrade .NET 4.7.1, that should fix the issue and this version will be the minimal version for the next module release.

CodeCyclone added a commit that referenced this issue Nov 30, 2018

Fixes and enhancements (#92)
* Updates to doc for New-PowerBIReport

* UserName and Credential overload for Connect-PowerBIServiceAccount (windows only)

* Adding Out-String vswhere output, issue #76

* Fixing issue where cmdlets couldn't load when executing on file shares, issue #87

* Adding GCC High and GCC Military to environment list

* Updating recommended .NET version to 4.7.1 for issues #82, #60

* Fix for New-PowerBIReport to import reports when user only has read-access

* Final change to enable Connect-PowerBIServiceAccount -Credential (without -ServicePrincipal). Addresses issues #59, #49, #51 and possibly #85

@CodeCyclone CodeCyclone referenced this issue Nov 30, 2018

Merged

Dev #96

CodeCyclone added a commit that referenced this issue Nov 30, 2018

Merge pull request #96 from Microsoft/dev
* New-PowerBIReport cmdlet (Steffen Kampmann contributed)
* UserName and Credential overload for Connect-PowerBIServiceAccount (windows only), #59, #49, #51 and possibly #85
* Adding Out-String vswhere output, issue #76
* Fixing issue where cmdlets couldn't load when executing on file shares, issue #87
* Adding GCC High and GCC Military to environment list
* Updating recommended .NET version to 4.7.1 for issues #82, #60
* Examples folder created
@CodeCyclone

This comment has been minimized.

Copy link
Collaborator

commented Dec 1, 2018

Updated documentation to use .NET 4.7.1

@CodeCyclone CodeCyclone closed this Dec 1, 2018

@titoSwin

This comment has been minimized.

Copy link

commented Dec 1, 2018

1.0.326 fixed some of the issues but it can't fix the OSPlatform issue on some environments. @titoSwin did you try to upgrade .NET 4.7.1, that should fix the issue and this version will be the minimal version for the next module release.

I am running .NET 4.7.2 and continue to get the error

@Toasterlabs

This comment has been minimized.

Copy link

commented Feb 14, 2019

This issue still exists. In my case I'm first building a connection to Azure using AzureRM. Running powerbi workspace cmdlets after that fail. Even when I use Disconnect-AzureAD.

[Newtonsoft.Json.JsonConvert].Module result remains the same.

MDStreamVersion : 131072
FullyQualifiedName : C:\Program Files\WindowsPowerShell\Modules\AzureAD\2.0.2.4\Newtonsoft.Json.dll
ModuleVersionId : 814f8268-fecd-454f-84c6-f965d394a6d8
MetadataToken : 1
ScopeName : Newtonsoft.Json.dll
Name : Newtonsoft.Json.dll
Assembly : Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
CustomAttributes : {}
ModuleHandle : System.ModuleHandle

Opening a new powershell window seems to work. So I'll try and run the powerbi cmdlets from a new workspace in Powershell and look at the results of that.

Is this an issue with the PowerBI cmdlets or normal behavior?

@liljath

This comment has been minimized.

Copy link

commented Feb 19, 2019

I had same issue.
This started after I decided to do some cleanup on the versions of PowerBIMgmt modules. In order to get it to work correctly I I had to install version 1.0.295.
I am also using AzureAD in same script. There I have v2.0.2.4
These 2 versions work together.

@Saltzmea

This comment has been minimized.

Copy link

commented Feb 19, 2019

I have the same issue with "Attempted to access an element as a type incompatible with the array" on the following install
ModuleType Version Name


Manifest 1.0.326 MicrosoftPowerBIMgmt
Binary 1.0.410 MicrosoftPowerBIMgmt.Data
Binary 1.0.410 MicrosoftPowerBIMgmt.Profile
Binary 1.0.410 MicrosoftPowerBIMgmt.Reports
Binary 1.0.410 MicrosoftPowerBIMgmt.Workspaces

@kjoebie

This comment has been minimized.

Copy link

commented Mar 20, 2019

Yep, got it also on version 1.0.410. Latest version of .Net installed.

But works when you start a new PS session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.