microsoft / Intune-PowerShell-SDK

Native PowerShell support for invoking Microsoft Intune Graph API to enable IT Pro scenario automation.
MIT License
308 stars 76 forks source link

System.Security.Cryptography.SHA256Cng fails to load #57

Open 3vi1 opened 5 years ago

3vi1 commented 5 years ago

Steps to reproduce

(Note: exact same results with up-to-date pwsh-preview.)

09:52:41 evil@P950ER ~/Downloads» pwsh
PowerShell 6.2.2
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /data/Downloads> install-module Microsoft.Graph.Intune
PS /data/Downloads> Import-Module Microsoft.Graph.Intune
PS /data/Downloads> Connect-MSGraph

Expected behavior

I expected to be prompted for credentials and connect to the graph API.

Actual behavior

Connect-MSGraph : Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
At line:1 char:1
+ Connect-MSGraph
+ ~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Connect-MSGraph], TypeLoadException
+ FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Intune.PowerShellGraphSDK.PowerShellCmdlets.Connect

Environment data

----                           -----
PSVersion                      6.2.2
PSEdition                      Core
GitCommitId                    6.2.2
OS                             Linux 5.2.0-8-generic #9-Ubuntu SMP Mon Jul 8 13:07:27 UTC 2019
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

This was tested with core 6 as well as the current pwsh-preview (PowerShell 7) github build from source (as of 8/6/2019) as well as current pwsh & pwsh-preview snaps on Ubuntu 18.04 and Ubuntu 19.10 (Eoan Ermine). See https://github.com/PowerShell/PowerShell/issues/10291.

I also reported this bug in the PowerShellModuleCoverage repo, https://github.com/PowerShell/PowerShellModuleCoverage/issues/9#event-2541388639, but they closed it and suggested I open it here. I'm not sure if it's because SHA256Cng is deprecated or if there's other reasoning.

SteveL-MSFT commented 5 years ago

Looks like this type isn't ported to .NET Core yet: https://github.com/dotnet/corefx/issues/27126

Softgrider commented 5 years ago

It installs always the "desk" version of the module. (Same problem as installing it into Azure Cloud Shell)

martinisoft1 commented 3 years ago

Same issue here. Trying to execute Intune cmdlets from a "deploymentscript" resource within an ARM Template. Under the hood a Azure Powershell Container is started where the exact same error occurs when running "connect-msgraph"

JeffBor commented 3 years ago

Any updates from the team on this issue? See: https://github.com/dotnet/runtime/issues/25044#issuecomment-520203003

killnine commented 1 year ago

Same issue here...

I have .NET Framework 4.8 installed and cannot install a lower version (4.7.1, for example).

EDIT: So I was running this in Powershell 7. When I opened it in the default PS that comes with Windows 10 it ran fine. Very bizarre.

achitofel commented 1 year ago

3 years later, still not resolved Powershell 7.26 running on Ubuntu 22.04 `Connect-MSGraph -ClientSecret $clientSecret

 |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 | Could not load type 'System.Security.Cryptography.SHA256Cng'

 | from assembly 'System.Core, Version=4.0.0.0, Culture=neutral,

 | PublicKeyToken=b77a5c561934e089'.

`

abelal83 commented 6 months ago

Just adding comment to hopefully raise this for attention as a solution was proposed https://github.com/dotnet/runtime/issues/25044#issuecomment-520203003