Tuesday, September 29, 2020

How to fix error could not load type 'Microsoft.SharePoint.Administration.DesignPackageType' error when import Microsoft.Online.SharePoint.PowerShell module

When you try to import Microsoft.Online.SharePoint.PowerShell module:

Import-Module -Name Microsoft.Online.SharePoint.PowerShell

you may get the following error:

Import-Module : Could not load type 'Microsoft.SharePoint.Administration.DesignPackageType' from assembly 'Microsoft.SharePoint.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.

also error can be the following:

Import-Module : Could not load type 'Microsoft.SharePoint.Client.Publishing.PortalLaunch' from assembly 'Microsoft.SharePoint.Client.Publishing, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.

The main problem is that PowerShell tries to use on-prem CSOM assemblies (which have version 16.0.0.0) instead of online (with version 16.1.x.x). There are some articles and posts which recommend to manually remove Microsoft.SharePoint.Client folders from GAC. It should not be done! Especially if you have on-prem Sharepoint installation on the same server – this installation may be broken because of that.

The reason of this error is conflicts between different versions of Sharepoint Online SDKs (SharePoint Client Components, SharePoint Online Management Shell). So correct way to solve this problem is the following:

1. Go to Control Panel > Programs and features and uninstall all instances of SharePoint Online Management Shell and SharePoint Client Components

2. Open PowerShell console and uninstall existing versions of Microsoft.Online.SharePoint.PowerShell module:

Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell -AllVersions

3. After that close PowerShell, open new session and install latest version of Microsoft.Online.SharePoint.PowerShell module:

Import-Module -Name Microsoft.Online.SharePoint.PowerShell

This time it should go without error.

3 comments:

  1. Thank you for the great instructions!!!!!! They resolved my issue. Much appreciated.

    ReplyDelete