pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
989 stars 662 forks source link

Import-Module SharePointPnPPowerShellOnline produces an error #2094

Open Glober777 opened 5 years ago

Glober777 commented 5 years ago

Reporting an Issue

I'm getting an error message when trying to import the module on one of my Windows Servers.

Expected behavior

The module should import without any errors (as it does on my other servers).

Actual behavior

The error that I'm seeing is:

PS> Import-Module SharePointPnPPowerShellOnline
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.9.1905.2\SharePointPnPPowerShellOnline.psd1'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.9.1905.2\SharePointPnP.PowerShell.Online.Commands.Format.ps1xml'.
VERBOSE: Populating RepositorySourceLocation property for module SharePointPnPPowerShellOnline.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.9.1905.2\SharePointPnP.PowerShell.Online.Commands.dll'.
Import-Module : Could not load type 'Microsoft.SharePoint.Client.HeaderLayoutType' from assembly 'Microsoft.SharePoint.Client, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.
At line:1 char:1
+ Import-Module SharePointPnPPowerShellOnline
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

PS> $Error[0] | fl * -Force

PSMessageDetails      :
Exception             : System.TypeLoadException: Could not load type 'Microsoft.SharePoint.Client.HeaderLayoutType' from assembly 'Microsoft.SharePoint.Client, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.
                           at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
                           at System.Reflection.RuntimeAssembly.GetExportedTypes()
                           at System.Management.Automation.Runspaces.PSSnapInHelpers.GetAssemblyTypes(Assembly assembly, String name)
                           at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzeModuleAssemblyWithReflection(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Boolean isModuleLoad, Dictionary`2& cmdlets, Dictionary`2&
                        aliases, Dictionary`2& providers, String helpFile, Type& randomCmdletToCheckLinkDemand, Type& randomProviderToCheckLinkDemand)
                           at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzePSSnapInAssembly(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Boolean isModuleLoad, Dictionary`2& cmdlets, Dictionary`2& aliases,
                        Dictionary`2& providers, String& helpFile)
                           at System.Management.Automation.Runspaces.InitialSessionState.ImportCmdletsFromAssembly(Assembly assembly, PSModuleInfo module)
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(PSModuleInfo parentModule, Boolean trySnapInName, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options
                        ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found, String shortModuleName, Boolean disableFormatUpdates)
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags
                        manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleNamedInManifest(PSModuleInfo parentModule, ModuleSpecification moduleSpecification, String moduleBase, Boolean searchModulePath, String prefix, SessionState ss, ImportModuleOptions
                        options, ManifestProcessingFlags manifestProcessingFlags, Boolean loadTypesFiles, Boolean loadFormatFiles, Object privateData, Boolean& found, String shortModuleName, Nullable`1 manifestLanguageMode)
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String moduleManifestPath, ExternalScriptInfo manifestScriptInfo, Hashtable data, Hashtable localizedData, ManifestProcessingFlags manifestProcessingFlags, Version
                        minimumVersion, Version maximumVersion, Version requiredVersion, Nullable`1 requiredModuleGuid, ImportModuleOptions& options, Boolean& containedErrors)
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags
                        manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingExtensions(PSModuleInfo parentModule, String moduleName, String fileBaseName, String extension, String moduleBase, String prefix, SessionState ss, ImportModuleOptions options,
                        ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingMultiVersionModuleBase(String moduleBase, ImportModuleOptions importModuleOptions, Boolean& found)
                           at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingModulePath(PSModuleInfo parentModule, Boolean found, IEnumerable`1 modulePath, String name, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags
                        manifestProcessingFlags, PSModuleInfo& module)
                           at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions importModuleOptions, String name)
                           at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()
                           at System.Management.Automation.CommandProcessor.ProcessRecord()
TargetObject          :
CategoryInfo          : NotSpecified: (:) [Import-Module], TypeLoadException
FullyQualifiedErrorId : System.TypeLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

PS> $Error[0].Exception | fl * -Force

Message        : Could not load type 'Microsoft.SharePoint.Client.HeaderLayoutType' from assembly 'Microsoft.SharePoint.Client, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.
TypeName       : Microsoft.SharePoint.Client.HeaderLayoutType
Data           : {}
InnerException :
TargetSite     : Void GetExportedTypes(System.Reflection.RuntimeAssembly, System.Runtime.CompilerServices.ObjectHandleOnStack)
StackTrace     :    at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
                    at System.Reflection.RuntimeAssembly.GetExportedTypes()
                    at System.Management.Automation.Runspaces.PSSnapInHelpers.GetAssemblyTypes(Assembly assembly, String name)
                    at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzeModuleAssemblyWithReflection(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Boolean isModuleLoad, Dictionary`2& cmdlets, Dictionary`2& aliases,
                 Dictionary`2& providers, String helpFile, Type& randomCmdletToCheckLinkDemand, Type& randomProviderToCheckLinkDemand)
                    at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzePSSnapInAssembly(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Boolean isModuleLoad, Dictionary`2& cmdlets, Dictionary`2& aliases, Dictionary`2&
                 providers, String& helpFile)
                    at System.Management.Automation.Runspaces.InitialSessionState.ImportCmdletsFromAssembly(Assembly assembly, PSModuleInfo module)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(PSModuleInfo parentModule, Boolean trySnapInName, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options,
                 ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found, String shortModuleName, Boolean disableFormatUpdates)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags
                 manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleNamedInManifest(PSModuleInfo parentModule, ModuleSpecification moduleSpecification, String moduleBase, Boolean searchModulePath, String prefix, SessionState ss, ImportModuleOptions options
                 ManifestProcessingFlags manifestProcessingFlags, Boolean loadTypesFiles, Boolean loadFormatFiles, Object privateData, Boolean& found, String shortModuleName, Nullable`1 manifestLanguageMode)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String moduleManifestPath, ExternalScriptInfo manifestScriptInfo, Hashtable data, Hashtable localizedData, ManifestProcessingFlags manifestProcessingFlags, Version minimumVersion,
                 Version maximumVersion, Version requiredVersion, Nullable`1 requiredModuleGuid, ImportModuleOptions& options, Boolean& containedErrors)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags
                 manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingExtensions(PSModuleInfo parentModule, String moduleName, String fileBaseName, String extension, String moduleBase, String prefix, SessionState ss, ImportModuleOptions options,
                 ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingMultiVersionModuleBase(String moduleBase, ImportModuleOptions importModuleOptions, Boolean& found)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingModulePath(PSModuleInfo parentModule, Boolean found, IEnumerable`1 modulePath, String name, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags,
                 PSModuleInfo& module)
                    at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions importModuleOptions, String name)
                    at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()
                    at System.Management.Automation.CommandProcessor.ProcessRecord()
HelpLink       :
Source         : mscorlib
HResult        : -2146233054

Steps to reproduce behavior

Import-Module SharePointPnPPowerShellOnline

The only difference of this server with others (where the module works just great) is that it has SharePoint DLLs already available in GAC (supposedly through MS Exchange 2016 and Skype for Business 2019 modules that were installed through MSI)

I have Fusion logs available from both servers (working and non-working) if needed.

Which version of the PnP-PowerShell Cmdlets are you using?

What is the version of the Cmdlet module you are running?

3.9.1905.2

How did you install the PnP-PowerShell Cmdlets?

ghost commented 5 years ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

Glober777 commented 5 years ago

By the way, I tried removing the PSGallery edition of the module and installing via the MSI but I doesn't work either

ghost commented 5 years ago

we have the exact same behavior.

Which version of the PnP-PowerShell Cmdlets are you using? PnP PowerShell for SharePoint 2013 PnP PowerShell for SharePoint 2016 . . : : PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running? . . : : 3.9.1905.2 && 3.9.1905.3

How did you install the PnP-PowerShell Cmdlets? MSI Installed downloaded from GitHub . . : : Installed through the PowerShell Gallery with Install-Module Other means

stpfarms commented 5 years ago

Same issue on Windows 10 fresh build. I tried also installing normal SharePoint Online commandlets but still no go.

Which version of the PnP-PowerShell Cmdlets are you using? . . : : PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running? . . : : 3.10.1906.0

How did you install the PnP-PowerShell Cmdlets? . . : : Installed through the PowerShell Gallery with Install-Module

Glober777 commented 5 years ago

I suspect that the issue is coming from the order in which the Initial Bind occurs in .NET (GAC comes prior to probing other locations). I wonder if the fix for this would be handling load of the assemblies through AppDomain.AssemblyResolve Event

Glober777 commented 4 years ago

Not sure exactly what it was, but when I tried importing the module of version 3.12.1908.1 the issue was no longer reoccurring, however, as soon as I updated to the latest version through PSGallery (3.17.2001.2) the issue reappeared, but it was complaining about another type from the SharePoint library.

ValerianHs commented 4 years ago

Same behaviour using 3.21.2005.1 on SharePoint 2013 Server

janandabhishek commented 4 years ago

Did we found solution for the above issue ? I am facing the issue while trying to import 3.12.1908.1.

stpfarms commented 4 years ago

To resolve the issue, (1) Navigate to C:\Windows\Microsoft.NET\assembly\GAC_MSIL (2) Remove the Microsoft.SharePoint.* assemblies (3) Uninstall the module with Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell

After reinstalling the module from the PowerShell gallery, the module worked flawlessly.

janandabhishek commented 4 years ago

Thanks a lot. We can not take the approach in a production farm. Also i am referring the dlls from a temp folder. Just wondering how this conflict is possible.