microsoftgraph / msgraph-sdk-powershell

Powershell SDK for Microsoft Graph
https://www.powershellgallery.com/packages/Microsoft.Graph
Other
686 stars 163 forks source link

Azure Automation Runbook - The type initializer for 'Azure.Core.Pipeline.DiagnosticScopeFactory' threw an exception. #2478

Open ibutbul1 opened 8 months ago

ibutbul1 commented 8 months ago

Describe the bug

Since the update of the Microsoft.Graph.Authentication on my Azure Automation account to the version 2.10, I'm unable to authenticate on with my App Registration when it's running on Azure.

To Reproduce Steps to reproduce the behavior:

  1. Execute Connect-MgGraph -ClientId $AppIdForGraph -TenantId $TenantId -CertificateThumbprint $CertificateThumbprint.Thumbprint -ErrorAction Stop | Out-Null
  2. See error at The type initializer for 'Azure.Core.Pipeline.DiagnosticScopeFactory' threw an exception.

Expected behavior

Successfully authenticate to the Graph API as it does so on the Hybrid Worker.

Module Version Hybrid Worker - 1.27.0 Azure Automation Account - 2.10

Environment Data

5.1

timayabi2020 commented 8 months ago

@ibutbul1 could you please provide the debug information. i.e. Connect-MgGraph -ClientId $AppIdForGraph -TenantId $TenantId -CertificateThumbprint $CertificateThumbprint.Thumbprint -Debug.

ibutbul1 commented 8 months ago

Connect-MgGraph : A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: The type initializer for 'Azure.Core.Pipeline.DiagnosticScopeFactory' threw an exception.


From: Tim @.> Sent: Tuesday, December 5, 2023 17:27 To: microsoftgraph/msgraph-sdk-powershell @.> Cc: Itzhak Butbul @.>; Mention @.> Subject: [!EXTERNAL!] Re: [microsoftgraph/msgraph-sdk-powershell] Azure Automation Runbook - The type initializer for 'Azure.Core.Pipeline.DiagnosticScopeFactory' threw an exception. (Issue #2478)

@ibutbul1https://github.com/ibutbul1 could you please provide the debug information. i.e. Connect-MgGraph -ClientId $AppIdForGraph -TenantId $TenantId -CertificateThumbprint $CertificateThumbprint.Thumbprint -Debug.

— Reply to this email directly, view it on GitHubhttps://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2478#issuecomment-1841019387, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AYDL3HMCPUNEN2IEXUSYMVTYH44MRAVCNFSM6AAAAABAHTY3RWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBRGAYTSMZYG4. You are receiving this because you were mentioned.Message ID: @.***>

The information contained in this email, including any attachments, may be privileged, confidential or protected by intellectual property rights, and is for the intended recipient only. If you have received this email in error, please notify the sender immediately and remove it from your system.

timayabi2020 commented 8 months ago

@ibutbul1 I was asking if it's possible to add -Debug parameter so that we can be able to see the verbose information concerning the error.

mdurini-swisscom commented 8 months ago

@timayabi2020 it's happening to me the same on my local machine: even adding the debug parameter, the error is the same, no extra details....I also tried to downgrade to 2.9.1, no effects.

ShachafGoldstein commented 5 months ago

https://stackoverflow.com/questions/78029415/connect-mggraph-cmdlet-throws-different-errors-in-powershell-5-1-and-7-4

solved it for me, doing Disconnect-PnPOnline before the connect-mggraph.

devops-fan commented 1 month ago

I had this error come up with in my script, where both PnP.Powershell and MS Graph API modules are being called. Unfortunately the fix of "Disconnect-PnPOnline" did not work for me. But the workaround fix created by @TobiasAT on PnP Bug #3637 (linked below) resolved the problem for me.

https://github.com/pnp/powershell/issues/3637