question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot load the module in PS Core

See original GitHub issue

Steps to reproduce

What steps can reproduce the defect? Please share the setup, commandline for vstest.console, sample project, target framework etc.

PS C:\Users\Stanislav> Import-Module PartnerCenter
Import-Module : Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
At line:1 char:1
+ Import-Module PartnerCenter
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

Expected behavior

Share the expected output

Successful import

Actual behavior

What is the behavior observed?

error

Diagnostic logs

Please share test platform diagnostics logs.
The logs may contain test assembly paths, kindly review and mask those before sharing.’

provided

Environment

Please share additional details about your environment. Version

PS C:\Users\Stanislav> $PSVersionTable.PSVersion

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
6      1      1

PS C:\Users\Stanislav> Get-Module -ListAvailable | Select-Object Version, Name

Version    Name
-------    ----
1.2.1      Az.Accounts
1.0.1      Az.Aks
1.0.1      Az.AnalysisServices
1.0.0      Az.ApiManagement
1.0.0      Az.ApplicationInsights
1.1.0      Az.Automation
1.0.0      Az.Batch
1.0.0      Az.Billing
1.0.1      Az.Cdn
1.0.0      Az.CognitiveServices
1.2.0      Az.Compute
1.0.0      Az.ContainerInstance
1.0.1      Az.ContainerRegistry
1.0.1      Az.DataFactory
1.0.0      Az.DataLakeAnalytics
1.0.2      Az.DataLakeStore
1.0.0      Az.DevTestLabs
1.0.0      Az.Dns
1.1.0      Az.EventGrid
1.0.0      Az.EventHub
1.0.0      Az.HDInsight
1.0.2      Az.IotHub
1.0.1      Az.KeyVault
1.1.0      Az.LogicApp
1.0.0      Az.MachineLearning
1.0.0      Az.MarketplaceOrdering
1.0.0      Az.Media
1.0.0      Az.Monitor
1.1.0      Az.Network
1.0.0      Az.NotificationHubs
1.0.0      Az.OperationalInsights
1.0.0      Az.PolicyInsights
1.0.0      Az.PowerBIEmbedded
1.0.1      Az.RecoveryServices
1.0.0      Az.RedisCache
1.0.0      Az.Relay
1.1.1      Az.Resources
1.0.0      Az.ServiceBus
1.0.1      Az.ServiceFabric
1.0.2      Az.SignalR
1.1.0      Az.Sql
1.0.2      Az.Storage
1.0.0      Az.StreamAnalytics
1.0.1      Az.TrafficManager
1.1.0      Az.Websites
2.0.2.4    AzureAD
1.5.1902.3 PartnerCenter
1.0.0      WindowsCompatibility
6.1.0.0    CimCmdlets
1.2.2.0    Microsoft.PowerShell.Archive
6.1.0.0    Microsoft.PowerShell.Diagnostics
6.1.0.0    Microsoft.PowerShell.Host
6.1.0.0    Microsoft.PowerShell.Management
6.1.0.0    Microsoft.PowerShell.Security
6.1.0.0    Microsoft.PowerShell.Utility
6.1.0.0    Microsoft.WSMan.Management
1.1.7.2    PackageManagement
1.6.7      PowerShellGet
0.0        PSDesiredStateConfiguration
6.1.0.0    PSDiagnostics
2.0.0      PSReadLine
1.1.2      ThreadJob
2.0.1.0    Appx
1.0.0.0    AssignedAccess
1.0.0.0    BitLocker
1.0.0.0    BranchCache
1.0        Defender
1.0.0.0    DirectAccessClientComponents
1.0.0.0    DnsClient
1.0.0.0    EventTracingManagement
1.0.0.0    HgsDiagnostics
2.0.0.0    Hyper-V
1.1        Hyper-V
3.0.0.0    Microsoft.PowerShell.Diagnostics
1.0.0.0    Microsoft.PowerShell.LocalAccounts
3.1.0.0    Microsoft.PowerShell.Management
1.0        MMAgent
2.0.0.0    NetAdapter
1.0.0.0    NetConnection
1.0.0.0    NetEventPacketCapture
2.0.0.0    NetLbfo
1.0.0.0    NetNat
2.0.0.0    NetQos
2.0.0.0    NetSecurity
1.0.0.0    NetSwitchTeam
1.0.0.0    NetTCPIP
1.0.0.0    NetWNV
1.0.0.0    NetworkConnectivityStatus
1.0.0.0    NetworkSwitchManager
1.0.0.0    NetworkTransition
1.0.0.0    PcsvDevice
1.0.0.0    PnpDevice
1.0.0.0    ScheduledTasks
2.0.0.0    SecureBoot
2.0.0.0    SmbShare
2.0.0.0    SmbWitness
1.0.0.0    StartLayout
2.0.0.0    Storage
2.0.0.0    TrustedPlatformModule
2.0.0.0    VpnClient
1.0.0.0    Wdac
1.0.0.0    WindowsDeveloperLicense
1.0        WindowsErrorReporting
1.0.0.0    WindowsUpdate
1.0.0.2    WindowsUpdateProvider

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
sqlsolvercommented, Jun 10, 2019

This exact error happens with other modules, including Azure AD, in PowerShell Core 6.2.1 even with version 4.8 of the .Net framework installed. You can resolve it in your session by manually loading System.Windows.Forms at the command line:

[System.Reflection.Assembly]::LoadFrom("C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Windows.Forms.dll")

prior to Import-Module -name [your module with Windows Forms dependency] but until this is resolved you may also want to add the .Net libraries to your path, and maybe even that module to the GAC.

0reactions
sqlsolvercommented, Jun 10, 2019

That leads to more of the same when I try to import the PartnerCenter.NetCore module:

Import-Module : Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.8.16603, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)
At line:1 char:1
+ Import-Module PartnerCenter.NetCore
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Import-Module], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
Read more comments on GitHub >

github_iconTop Results From Across the Web

Import-Module : Could not load file or assembly 'System. ...
I'm unable to run PnP PowerShell commands using PowerShell ISE in administrative mode. Getting following error PS C:\WINDOWS\system32> ...
Read more >
no valid module file was found in any module directory ...
Fix "Import-Module: The specified module 'Module Name' was not loaded because no valid module file was found in any module directory" error in...
Read more >
Powershell import-module doesn't find modules
My finding with PS 5.0 on Windows 7: $ENV:PsModulePath has to end with a . This normally means it will load all modules...
Read more >
Cannot install powershell modules - Microsoft Q&A
My problem is that I am not able to install modules to my powershell console. Example: Install-module -Name AzureAD. Copy.
Read more >
How to install the PowerShell Active Directory module
Install the AD module on PowerShell Core 6.x on a Windows computer. Install RSAT with the ... On Linux and macOS you can't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found