-
Notifications
You must be signed in to change notification settings - Fork 192
Connect-MgGraph failing consistently with TypeInitializationException exception thrown for Azure.Identity.AuthenticationRecord #2284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
On request from the support technician which is working on the support case we have also reported an issue for here (that too on request by the support technician), we have tried to authenticate and run the
|
I am having the exact same issue, running our script with Powershell 7 works fine, but we cannot introduce Powershell 7 where the script needs to be run. On the same system, Connect-AzAccount fails as well with Windows Powershell 5.1, this could be related to the root cause of the issue:
|
#2148 this issue could be related |
With the comment from @fujiant about issues also with However, the version of Az.Accounts on my system is a bit dated (while Microsoft.Graph.Authentication is fully up-to-date) as you can see below:
|
I tried to downgrade Microsoft.Graph.Authentication version to 1.28.0 and it worked briefly. The only reliable workaround I found was not to call Connect-AzAccount and Connect-MgGraph in the same Powershell script, eg. not including the Az module and Graph module in the same file. |
@TrondHaugmo could you please share the output of this command |
Hello @timayabi2020, here is the requested output from running
|
@TrondHaugmo apologies for the delayed response. I tried to reproduce the issue based on all the scenarios you had highlighted, and none yielded results similar to yours. The connection was successful without any errors. |
I also receive same error, after logging in using Azure AD Administrator account, grant permissions in the consent screen.
Powershell : 7.0.2 |
@unnieayilliath please confirm the Az module version you are using. If its an old version, consider upgrading to the latest version. |
I dont' have Az module installed on this machine. |
Hello @timayabi2020, I apologize for the delayed response after you recommended updating Az-modules on the machine in question. Another task with even higher priority (according to my manager) has unfortunately taken all my time (day and night) the last few days. However, today I have focused on this challenge again, and it looks like you really "hit the nail on the head" with putting focus on the Az-modules. We use cmdlets from them quite regularly on the machine in question, but since they have just worked lately we have been a bit lazy and not updated them for a while. Today I performed some "housekeeping" and updated all Az-modules to the most recent version (main version 10.4.1, lot of different individual versions on each of the detailed modules), removed any old module versions in the process as well, and then also installed the very latest Microsoft.Graph modules (2.6.1), after first removing the Beta-version which was installed in an earlier attempt to find a solution. With this "setup" (and the required Azure AD/Entra ID roles activated through PIM) I was successfully able to run
I could also execute commands and make updates to Azure AD/Entra ID resources through for example the use of the |
Still having the issue even with the latest Az module version and the latest Graph module. If both are used in the same file, there'll be errors. I am getting errors on both Powershell 5.1 and 7.0. |
Yes, I am still facing the same issue:
|
I have the same problem here: I enabled defender for Identity in Azure then these commands stopped working for mggraph. PS C:\Windows\system32> Import-Module Microsoft.Graph.Authentication Import-Module : Could not load file or assembly 'Azure.Core, Version=1.33.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file
PS C:\Windows\system32> Update-Module Microsoft.Graph PS C:\Windows\system32> Import-Module Microsoft.Graph.Authentication Import-Module : Could not load file or assembly 'Azure.Core, Version=1.33.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file
PS C:\Windows\system32> |
Found a solution: when installing the modules, add -force at the end to update the module to a working version. do the following: Then try importing. it should work after that. |
Using latest version of Microsoft.Graph.
Connect-MgGraph line results in: If I just run
|
It appears to be related to the PowerShell extension for VSCode. Kill the terminal and launch a fresh |
Not here, I am runing powershell 5.1, I have uninstalled vscode-powershell just for test:
|
We are trying to start using the Microsoft.Graph PS modules for our Azure AD scripting needs, but even after installing the very latest versions of the modules (now also having tried the latest beta versions) on my system, I still get an error stating "The type initializer for 'Azure.Identity.AuthenticationRecord' threw an exception" (TypeInitializationException) when running "Connect-MgGraph".
We have opened a support call through our Unified Support Agreement (Case tracking ID: 2307070050003124), but after working with the support technician for a while (which have had us report on what are the currently installed Microsoft.Graph modules and requested us to fully remove them and then install the very latest versions including the most recent beta version in several "rounds") we are still consistently getting the same error every time we try to run Connect-MgGraph, and the support technician has thus recommended us to also register this as an issue here on GitHub.
This is the command we try to run, which obviously brings up a prompt to perform authentication: Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"
I authenticate with my Azure AD admin account which has the following AD roles activated (through PIM) in advance of running the command:
The authentication is successful it seems, and the very first time we tried this we also had to go through an admin-consent process, but that now seems properly registered in our Azure AD tenant as that does not show up after that first attempt. Now we just go through MFA and then the authentication dialog briefly states that authentication was successful before it close. However, immediately after we get the mentioned error as you can see in the example screenshot below:

The machine where I'm encountering the issue is running Windows Server 2016 with PowerShell 5.1 (see version details below). The support technician has recommended us to try using PowerShell 7.x, but for various reasons we cannot introduce that version of PowerShell on the system in question, and the Microsoft.Graph modules are officially supported also on PowerShell 5.1 so we need to figure out why it does not work in our case. The output from $PSVersionTable on the system looks like this:
Reproducing the issue
Full set of steps that reproduce the behavior:
Get-Module
to show what modules are automatically loaded:Get-Module -FullyQualifiedName Microsoft.Graph* -ListAvailable
to verify that I only have one set of Microsoft.Graph modules installed, and as you can see from the screenshot below it is now the beta-edition of the most recent version (2.4.0) that are installed on the system:Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"
and after completing the authentication including MFA through the pop-up dialog, then the error is immediately encountered:Expected behavior
The expected behavior is that executing
Connect-MgGraph
would complete successfully without returning an error.Debug Output
I have also tried running the
Connect-MgGraph
cmdlet with the same parameters, but also adding-Debug
, and the full output of that looks like this (requestID's/correlationId's anonymized):DEBUG: InteractiveBrowserCredential.Authenticate invoked. Scopes: [ User.Read.All, Group.ReadWrite.All ] ParentRequestId:
DEBUG: Executing interactive authentication workflow inline.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:52Z - x1111111-xxxx-11xx-
8f64-71f2f9addfaf] MSAL MSAL.Desktop with assembly version '4.49.1.0'. CorrelationId( x1111111-xxxx-11xx-8f64-71f2f9addfaf
)
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] === InteractiveParameters Data ===
LoginHint provided: False
User provided: False
UseEmbeddedWebView: NotSpecified
ExtraScopesToConsent:
Prompt: select_account
HasCustomWebUi: False
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf]
=== Request Data ===
Authority Provided? - True
Scopes - User.Read.All Group.ReadWrite.All
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenInteractive
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - x1111111-xxxx-11xx-8f64-71f2f9addfaf
UserAssertion set: False
LongRunningOboCacheKey set: False
Region configured:
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] === Token Acquisition (InteractiveRequest) started:
Scopes: User.Read.All Group.ReadWrite.All
Authority Host: login.microsoftonline.com
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [Instance Discovery] Instance discovery is enabled and will be performed
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Fetching instance discovery from the network from host login.microsoftonline.com.
DEBUG: Request [xxx1111x-1xx1-111x-99c3-58188404c787] GET https://login.microsoftonline.com/common/discovery/instance?api-v
ersion=1.1&authorization_endpoint=REDACTED
x-client-SKU:REDACTED
x-client-Ver:REDACTED
x-client-CPU:REDACTED
x-client-OS:REDACTED
client-request-id:REDACTED
return-client-request-id:REDACTED
x-app-name:REDACTED
x-app-ver:REDACTED
x-ms-client-request-id:xxx1111x-1xx1-111x-99c3-58188404c787
x-ms-return-client-request-id:true
User-Agent:azsdk-net-Identity/1.9.0 (.NET Framework 4.8.4645.0; Microsoft Windows 10.0.14393 )
client assembly: Azure.Identity
DEBUG: Response [xxx1111x-1xx1-111x-99c3-58188404c787] 200 OK (00.1s)
Strict-Transport-Security:REDACTED
X-Content-Type-Options:REDACTED
Access-Control-Allow-Origin:REDACTED
Access-Control-Allow-Methods:REDACTED
client-request-id:REDACTED
x-ms-request-id:111111xx-1111-1xx1-84b9-cf2e18138a00
x-ms-ests-server:REDACTED
X-XSS-Protection:REDACTED
Cache-Control:max-age=86400, private
Content-Type:application/json; charset=utf-8
P3P:REDACTED
Set-Cookie:REDACTED
Date:Mon, 04 Sep 2023 07:37:56 GMT
Content-Length:950
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Authority validation enabled? True.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Authority validation - is known env? True.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:37:57Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Using legacy embedded browser.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [Legacy WebView] Redirect URI was reached. Stopping WebView navigation...
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] An authorization code was retrieved from the /authorize endpoint.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Exchanging the auth code for tokens.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] === InteractiveParameters Data ===
LoginHint provided: False
User provided: False
UseEmbeddedWebView: NotSpecified
ExtraScopesToConsent:
Prompt: select_account
HasCustomWebUi: False
DEBUG: Request [1111x11x-1111-1111-9096-cf017e3724e1] POST https://login.microsoftonline.com/common/oauth2/v2.0/token
x-client-SKU:REDACTED
x-client-Ver:REDACTED
x-client-CPU:REDACTED
x-client-OS:REDACTED
x-anchormailbox:REDACTED
x-client-current-telemetry:REDACTED
x-client-last-telemetry:REDACTED
x-ms-PKeyAuth:REDACTED
x-ms-lib-capability:REDACTED
client-request-id:REDACTED
return-client-request-id:REDACTED
x-app-name:REDACTED
x-app-ver:REDACTED
Content-Type:application/x-www-form-urlencoded
x-ms-client-request-id:1111x11x-1111-1111-9096-cf017e3724e1
x-ms-return-client-request-id:true
User-Agent:azsdk-net-Identity/1.9.0 (.NET Framework 4.8.4645.0; Microsoft Windows 10.0.14393 )
client assembly: Azure.Identity
DEBUG: Response [1111x11x-1111-1111-9096-cf017e3724e1] 200 OK (00.3s)
Pragma:no-cache
Strict-Transport-Security:REDACTED
X-Content-Type-Options:REDACTED
client-request-id:REDACTED
x-ms-request-id:11xxx1xx-1111-111x-b139-4628de696700
x-ms-ests-server:REDACTED
x-ms-clitelem:REDACTED
X-XSS-Protection:REDACTED
Cache-Control:no-store, no-cache
Content-Type:application/json; charset=utf-8
Expires:-1
P3P:REDACTED
Set-Cookie:REDACTED
Date:Mon, 04 Sep 2023 07:38:19 GMT
Content-Length:5460
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Checking client info returned from the server..
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Saving token response to cache..
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [SaveTokenResponseAsync] Saving AT in cache and removing overlapping ATs...
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Looking for scopes for the authority in the cache which intersect with User.Read.All Group.ReadWrite.All
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Intersecting scope entries count - 1
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Matching entries after filtering by user - 1
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [SaveTokenResponseAsync] Saving Id Token and Account in cache ...
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [SaveTokenResponseAsync] Saving RT in cache...
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] [AdalCacheOperations] Serializing token cache with 1 items.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf]
=== Token Acquisition finished successfully:
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] AT expiration time: 9/5/2023 7:38:19 AM +00:00, scopes: Application.Read.All AuditLog.Read.All CrossT
enantInformation.ReadBasic.All Group.Read.All Group.ReadWrite.All openid Policy.Read.All profile RoleAssignmentSchedule.Rea
d.Directory RoleEligibilitySchedule.Read.Directory RoleManagement.Read.Directory User.Read User.Read.All email. source: Ide
ntityProvider
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows Server 2016 Standard [2023-09-04 07:38:20Z - x1111111-xxxx-11xx-8f64-71f2f9addfaf] Fetched access token from host login.microsoftonline.com.
DEBUG: InteractiveBrowserCredential.Authenticate succeeded. Scopes: [ User.Read.All, Group.ReadWrite.All ] ParentRequestId:
ExpiresOn: 2023-09-05T07:38:19.8408559+00:00
Connect-MgGraph : The type initializer for 'Azure.Identity.AuthenticationRecord' threw an exception.
At line:1 char:1
Module Version
The text was updated successfully, but these errors were encountered: