Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.15k stars 3.78k forks source link

Connect-AzAccount : ClientCertificateCredential authentication failed: Method not found: #20526

Open mark3grahams opened 1 year ago

mark3grahams commented 1 year ago

Description

Seemingly randomly, I receive the following error when I log on as a service principal using a certificate. Restarting the terminal in VSCode sometimes resolves it. Sometimes it does not.

Issue script & Debug output

Connect-AzAccount -CertificateThumbprint $Thumbprint -ApplicationId $ApplicationId -Tenant $TenantId -ServicePrincipal -ErrorAction Stop 
Connect-AzAccount : ClientCertificateCredential authentication failed: Method not found: 
'Microsoft.Identity.Client.ConfidentialClientApplicationBuilder Microsoft.Identity.Client.ConfidentialClientApplicationBuilder.WithClientAssertio 
n(System.Func`2<System.Threading.CancellationToken,System.Threading.Tasks.Task`1<System.String>>)'.
At line:1 char:1
+ Connect-AzAccount -CertificateThumbprint $Thumbprint -ApplicationId $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Connect-AzAccount], AuthenticationFailedException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand

DEBUG: 5:54:39 PM - ConnectAzureRmAccountCommand begin processing with ParameterSet 'ServicePrincipalCertificateWithSubscriptionId'.
DEBUG: 5:54:39 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True]. 
DEBUG: 5:54:39 PM - [ConfigManager] Got nothing from [DefaultSubscriptionForLogin], Module = [], Cmdlet = []. Returning default value [].      
DEBUG: 5:54:39 PM - Autosave setting from startup session: 'CurrentUser'
DEBUG: 5:54:39 PM - No autosave setting detected in environment variable 'AzContextAutoSave'.
DEBUG: 5:54:39 PM - Using Autosave scope 'CurrentUser'
DEBUG: 5:54:39 PM - [ServicePrincipalAuthenticator] Calling ClientCertificateCredential.GetTokenAsync - 
Thumbprint:'', ApplicationId:'',
TenantId:'', Scopes:'https://management.core.windows.net//.default',
AuthorityHost:'https://login.microsoftonline.com/'
DEBUG: ClientCertificateCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId:
DEBUG: ClientCertificateCredential.GetToken was unable to retrieve an access token. Scopes: [ https://management.core.windows.net//.default ]  
ParentRequestId:  Exception: Azure.Identity.AuthenticationFailedException (0x80131500): ClientCertificateCredential authentication failed:     
Method not found: 'Microsoft.Identity.Client.ConfidentialClientApplicationBuilder
Microsoft.Identity.Client.ConfidentialClientApplicationBuilder.WithClientAssertion(System.Func`2<System.Threading.CancellationToken,System.Thr 
eading.Tasks.Task`1<System.String>>)'.
 ---> System.MissingMethodException (0x80131513): Method not found: 'Microsoft.Identity.Client.ConfidentialClientApplicationBuilder
Microsoft.Identity.Client.ConfidentialClientApplicationBuilder.WithClientAssertion(System.Func`2<System.Threading.CancellationToken,System.Thr 
eading.Tasks.Task`1<System.String>>)'.
DEBUG: Azure.Identity.AuthenticationFailedException: ClientCertificateCredential authentication failed: Method not found: 
'Microsoft.Identity.Client.ConfidentialClientApplicationBuilder
Microsoft.Identity.Client.ConfidentialClientApplicationBuilder.WithClientAssertion(System.Func`2<System.Threading.CancellationToken,System.Thr 
eading.Tasks.Task`1<System.String>>)'. ---> System.MissingMethodException: Method not found:
'Microsoft.Identity.Client.ConfidentialClientApplicationBuilder
Microsoft.Identity.Client.ConfidentialClientApplicationBuilder.WithClientAssertion(System.Func`2<System.Threading.CancellationToken,System.Thr 
eading.Tasks.Task`1<System.String>>)'.
   at Azure.Identity.MsalConfidentialClient.<CreateClientAsync>d__16.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at Azure.Identity.MsalConfidentialClient.CreateClientAsync(Boolean async, CancellationToken cancellationToken)
   at Azure.Identity.MsalClientBase`1.<GetClientAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Azure.Identity.MsalConfidentialClient.<AcquireTokenForClientCoreAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Azure.Identity.MsalConfidentialClient.<AcquireTokenForClientAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Azure.Identity.ClientCertificateCredential.<GetTokenAsync>d__25.MoveNext()
   --- End of inner exception stack trace ---
   at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex, String additionalMessage)
   at Azure.Identity.ClientCertificateCredential.<GetTokenAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.PowerShell.Authenticators.MsalAccessToken.<GetAccessTokenAsync>d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.Authenticate(IAzureAccount account, IAzureEnvironment     
environment, String tenant, SecureString password, String promptBehavior, Action`1 promptAction, IAzureTokenCache tokenCache, String
resourceId)
   at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.AcquireAccessToken(IAzureAccount account, IAzureEnvironment environment, 
 String tenantId, SecureString password, String promptBehavior, Action`1 promptAction, String resourceId)
   at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.Login(IAzureAccount account, IAzureEnvironment environment, String       
tenantIdOrName, String subscriptionId, String subscriptionName, SecureString password, Boolean skipValidation, Action`1 promptAction, String   
name, Boolean shouldPopulateContextList, Int32 maxContextPopulation, String authScope)
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass127_2.<ExecuteCmdlet>b__5()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass127_0.<ExecuteCmdlet>b__1(AzureRmProfile localProfile,    
RMProfileClient profileClient, String name)
DEBUG: 5:54:39 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
WARNING: Cannot Connect to Azure as the Service Principal! ClientCertificateCredential authentication failed: Method not found:
'Microsoft.Identity.Client.ConfidentialClientApplicationBuilder
Microsoft.Identity.Client.ConfidentialClientApplicationBuilder.WithClientAssertion(System.Func`2<System.Threading.CancellationToken,System.Thr 
eading.Tasks.Task`1<System.String>>)'.

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.20348.1366
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.20348.1366
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module versions

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     2.10.4     Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}

Error output

DEBUG: 5:56:20 PM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 5:56:20 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True]. 
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release.  Please change any scripts that use this alias to use `Resolve-AzError`
instead.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes  
in Azure PowerShell.

 HistoryId: 4

Message        : ClientCertificateCredential authentication failed: Method not found:
                 'Microsoft.Identity.Client.ConfidentialClientApplicationBuilder Microsoft.Identity.Client.ConfidentialClientApplicationBuilde 
                 r.WithClientAssertion(System.Func`2<System.Threading.CancellationToken,System.Threading.Tasks.Task`1<System.String>>)'.       
StackTrace     :    at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex, String additionalMessage)
                    at Azure.Identity.ClientCertificateCredential.<GetTokenAsync>d__25.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Microsoft.Azure.PowerShell.Authenticators.MsalAccessToken.<GetAccessTokenAsync>d__33.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.Authenticate(IAzureAccount account,      
                 IAzureEnvironment environment, String tenant, SecureString password, String promptBehavior, Action`1 promptAction,
                 IAzureTokenCache tokenCache, String resourceId)
                    at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.AcquireAccessToken(IAzureAccount account,
                 IAzureEnvironment environment, String tenantId, SecureString password, String promptBehavior, Action`1 promptAction, String   
                 resourceId)
                    at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.Login(IAzureAccount account, IAzureEnvironment
                 environment, String tenantIdOrName, String subscriptionId, String subscriptionName, SecureString password, Boolean 
                 skipValidation, Action`1 promptAction, String name, Boolean shouldPopulateContextList, Int32 maxContextPopulation, String     
                 authScope)
                    at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass127_2.<ExecuteCmdlet>b__5()
                    at System.Threading.Tasks.Task`1.InnerInvoke()
                    at System.Threading.Tasks.Task.Execute()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at
                 Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass127_0.<ExecuteCmdlet>b__1(AzureRmProfile       
                 localProfile, RMProfileClient profileClient, String name)
                    at Microsoft.Azure.Commands.Profile.Common.AzureContextModificationCmdlet.ModifyContext(Action`2 contextAction)
                    at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.SetContextWithOverwritePrompt(Action`3 setContextAction)  
                    at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : Azure.Identity.AuthenticationFailedException
InvocationInfo : {Connect-AzAccount}
Line           :             Connect-AzAccount -CertificateThumbprint $Thumbprint -ApplicationId $ApplicationId -Tenant $TenantId
                 -ServicePrincipal -ErrorAction Stop |  Out-Null

Position       : At .ps1:94 char:13
                 +             Connect-AzAccount -CertificateThumbprint $Thumbprint -App ...
                 +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 4

Message        : Method not found: 'Microsoft.Identity.Client.ConfidentialClientApplicationBuilder Microsoft.Identity.Client.ConfidentialClien
                 tApplicationBuilder.WithClientAssertion(System.Func`2<System.Threading.CancellationToken,System.Threading.Tasks.Task`1<System 
                 .String>>)'.
StackTrace     :    at Azure.Identity.MsalConfidentialClient.<CreateClientAsync>d__16.MoveNext()
                    at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
                    at Azure.Identity.MsalConfidentialClient.CreateClientAsync(Boolean async, CancellationToken cancellationToken)
                    at Azure.Identity.MsalClientBase`1.<GetClientAsync>d__20.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Azure.Identity.MsalConfidentialClient.<AcquireTokenForClientCoreAsync>d__18.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Azure.Identity.MsalConfidentialClient.<AcquireTokenForClientAsync>d__17.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Azure.Identity.ClientCertificateCredential.<GetTokenAsync>d__25.MoveNext()
Exception      : System.MissingMethodException
InvocationInfo : {Connect-AzAccount}
Line           :             Connect-AzAccount -CertificateThumbprint $Thumbprint -ApplicationId $ApplicationId -Tenant $TenantId
                 -ServicePrincipal -ErrorAction Stop |  Out-Null

Position       : At .ps1:94 char:13
                 +             Connect-AzAccount -CertificateThumbprint $Thumbprint -App ...
                 +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 4

Message        : No modules were removed. Verify that the specification of modules to remove is correct and those modules exist in the
                 runspace.
StackTrace     :
Exception      : System.InvalidOperationException
InvocationInfo : {Remove-Module}
Line           :   Remove-Module AzureAD -ErrorAction SilentlyContinue

Position       : At .ps1:106 char:3
                 +   Remove-Module AzureAD -ErrorAction SilentlyContinue
                 +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 4

Message        : The specified module 'C:\Program
                 Files\DesiredStateConfiguration\1.0.0.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psd1' was not loaded  
                 because no valid module file was found in any module directory.
StackTrace     :
Exception      : System.IO.FileNotFoundException
InvocationInfo : {Import-Module}
Line           :
Position       :
HistoryId      : 4

Message        : The specified module 'C:\Program 
                 Files\DesiredStateConfiguration\1.0.0.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psd1' was not loaded  
                 because no valid module file was found in any module directory.
StackTrace     :
Exception      : System.IO.FileNotFoundException
InvocationInfo : {Import-Module}
Line           :
Position       :
HistoryId      : 4

Message        : The specified module 'C:\Program
                 Files\DesiredStateConfiguration\1.0.0.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psd1' was not loaded  
                 because no valid module file was found in any module directory.
StackTrace     :
Exception      : System.IO.FileNotFoundException
InvocationInfo : {Import-Module}
Line           :
Position       :
HistoryId      : 4

Message        : The specified module 'C:\Program
                 Files\DesiredStateConfiguration\1.0.0.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psd1' was not loaded  
                 because no valid module file was found in any module directory.
StackTrace     :
Exception      : System.IO.FileNotFoundException
InvocationInfo : {Import-Module}
Line           :
Position       :
HistoryId      : 4

   HistoryId: 1

Message        : ClientCertificateCredential authentication failed: Method not found:
                 'Microsoft.Identity.Client.ConfidentialClientApplicationBuilder Microsoft.Identity.Client.ConfidentialClientApplicationBuilde 
                 r.WithClientAssertion(System.Func`2<System.Threading.CancellationToken,System.Threading.Tasks.Task`1<System.String>>)'.       
StackTrace     :    at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex, String additionalMessage)
                    at Azure.Identity.ClientCertificateCredential.<GetTokenAsync>d__25.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Microsoft.Azure.PowerShell.Authenticators.MsalAccessToken.<GetAccessTokenAsync>d__33.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.Authenticate(IAzureAccount account,      
                 IAzureEnvironment environment, String tenant, SecureString password, String promptBehavior, Action`1 promptAction,
                 IAzureTokenCache tokenCache, String resourceId)
                    at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.AcquireAccessToken(IAzureAccount account,
                 IAzureEnvironment environment, String tenantId, SecureString password, String promptBehavior, Action`1 promptAction, String   
                 resourceId)
                    at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.Login(IAzureAccount account, IAzureEnvironment
                 environment, String tenantIdOrName, String subscriptionId, String subscriptionName, SecureString password, Boolean
                 skipValidation, Action`1 promptAction, String name, Boolean shouldPopulateContextList, Int32 maxContextPopulation, String     
                 authScope)
                    at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass127_2.<ExecuteCmdlet>b__5()
                    at System.Threading.Tasks.Task`1.InnerInvoke()
                    at System.Threading.Tasks.Task.Execute()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at
                 Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass127_0.<ExecuteCmdlet>b__1(AzureRmProfile       
                 localProfile, RMProfileClient profileClient, String name)
                    at Microsoft.Azure.Commands.Profile.Common.AzureContextModificationCmdlet.ModifyContext(Action`2 contextAction)
                    at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.SetContextWithOverwritePrompt(Action`3 setContextAction)  
                    at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : Azure.Identity.AuthenticationFailedException
InvocationInfo : {Connect-AzAccount}
Line           :             Connect-AzAccount -CertificateThumbprint $Thumbprint -ApplicationId $ApplicationId -Tenant $TenantId
                 -ServicePrincipal -ErrorAction Stop |  Out-Null

Position       : At .ps1:94 char:13
                 +             Connect-AzAccount -CertificateThumbprint $Thumbprint -App ...
                 +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 1

Message        : Method not found: 'Microsoft.Identity.Client.ConfidentialClientApplicationBuilder Microsoft.Identity.Client.ConfidentialClien
                 tApplicationBuilder.WithClientAssertion(System.Func`2<System.Threading.CancellationToken,System.Threading.Tasks.Task`1<System 
                 .String>>)'.
StackTrace     :    at Azure.Identity.MsalConfidentialClient.<CreateClientAsync>d__16.MoveNext()
                    at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
                    at Azure.Identity.MsalConfidentialClient.CreateClientAsync(Boolean async, CancellationToken cancellationToken)
                    at Azure.Identity.MsalClientBase`1.<GetClientAsync>d__20.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Azure.Identity.MsalConfidentialClient.<AcquireTokenForClientCoreAsync>d__18.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Azure.Identity.MsalConfidentialClient.<AcquireTokenForClientAsync>d__17.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Azure.Identity.ClientCertificateCredential.<GetTokenAsync>d__25.MoveNext()
Exception      : System.MissingMethodException
InvocationInfo : {Connect-AzAccount}
Line           :             Connect-AzAccount -CertificateThumbprint $Thumbprint -ApplicationId $ApplicationId -Tenant $TenantId
                 -ServicePrincipal -ErrorAction Stop |  Out-Null

Position       : At .ps1:94 char:13
                 +             Connect-AzAccount -CertificateThumbprint $Thumbprint -App ...
                 +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 1

Message        : You must call the Connect-AzureAD cmdlet before calling any other cmdlets.
StackTrace     :    at Microsoft.Open.Azure.AD.CommonLibrary.AzureSession.ClientAuthenticated() in
                 C:\__w\1\s\src\dev\PowerShell.V2\CommonLibrary\Models\AzureSession.cs:line 110
                    at System.Management.Automation.Cmdlet.DoBeginProcessing()
                    at System.Management.Automation.CommandProcessorBase.DoBegin()
Exception      : Microsoft.Open.Azure.AD.CommonLibrary.AadNeedAuthenticationException
InvocationInfo : {Get-AzureADTenantDetail}
Line           :       $Var = Get-AzureADTenantDetail

Position       : At .ps1:112 char:14
                 +       $Var = Get-AzureADTenantDetail
                 +              ~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 1

Message        : No modules were removed. Verify that the specification of modules to remove is correct and those modules exist in the
                 runspace.
StackTrace     :
Exception      : System.InvalidOperationException
InvocationInfo : {Remove-Module}
Line           :   Remove-Module AzureAD -ErrorAction SilentlyContinue

Position       : At .ps1:106 char:3
                 +   Remove-Module AzureAD -ErrorAction SilentlyContinue
                 +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 1

Message        : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
StackTrace     :    at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
                    at System.Reflection.RuntimeModule.GetTypes()
                    at System.Reflection.Assembly.GetTypes()
                    at Microsoft.PowerShell.Commands.AddTypeCommand.LoadAssemblyFromPathOrName(List`1 generatedTypes)
                    at Microsoft.PowerShell.Commands.AddTypeCommand.EndProcessing()
                    at System.Management.Automation.CommandProcessorBase.Complete()
Exception      : System.Reflection.ReflectionTypeLoadException
InvocationInfo : {Add-Type}
Line           :                     Add-Type -Path $_.FullName -ErrorAction Ignore | Out-Null

Position       : At \WindowsPowerShell\Modules\Az.Accounts\2.10.4\Az.Accounts.psm1:39     
                 char:21
                 + ...                Add-Type -Path $_.FullName -ErrorAction Ignore | Out-N ...
                 +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 1

Message        : The specified module 'C:\Program
                 Files\DesiredStateConfiguration\1.0.0.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psd1' was not loaded  
                 because no valid module file was found in any module directory.
StackTrace     :
Exception      : System.IO.FileNotFoundException
InvocationInfo : {Import-Module}
Line           :
Position       :
HistoryId      : 1

Message        : The specified module 'C:\Program
                 Files\DesiredStateConfiguration\1.0.0.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psd1' was not loaded  
                 because no valid module file was found in any module directory.
StackTrace     :
Exception      : System.IO.FileNotFoundException
InvocationInfo : {Import-Module}
Line           :
Position       :
HistoryId      : 1

Message        : The specified module 'C:\Program 
                 Files\DesiredStateConfiguration\1.0.0.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psd1' was not loaded  
                 because no valid module file was found in any module directory.
StackTrace     :
Exception      : System.IO.FileNotFoundException
InvocationInfo : {Import-Module}
Line           :
Position       :
HistoryId      : 1

Message        : The specified module 'C:\Program
                 Files\DesiredStateConfiguration\1.0.0.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psd1' was not loaded  
                 because no valid module file was found in any module directory.
StackTrace     :
Exception      : System.IO.FileNotFoundException
InvocationInfo : {Import-Module}
Line           :
Position       :
HistoryId      : 1

The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.

DEBUG: AzureQoSEvent:  Module: Az.Accounts:2.10.4; CommandName: Resolve-AzError; PSVersion: 5.1.20348.1366; IsSuccess: True; Duration:
00:00:00.4008530
DEBUG: 5:56:20 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 5:56:20 PM - ResolveError end processing.
dingmeng-xue commented 1 year ago

@mark3grahams , thanks for reporting. Normally, this random "Method not found" error is due to unexpected assembly was imported into PowerShell console due to other modules. When you hit the issue again, please execute below script and check where Microsoft.Identity.* and Azure.Identity were loaded from.

[System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location | Sort-Object -Property FullName | Select-Object -Property FullName, Location
mark3grahams commented 1 year ago

Will do. It will likely be a few days or so.

mark3grahams commented 1 year ago

FullName Location Azure.Identity, Version=1.6.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8 \Documents\WindowsPowerShell\Modules\Az.Accounts\2.10.4\PreloadAssemblies\Azure.Identity.dll

Microsoft.Identity.Client, Version=4.29.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae \Documents\WindowsPowerShell\Modules\MicrosoftTeams\4.7.0\net472\Microsoft.Identity.Client.dll

Microsoft.Identity.Client, Version=4.36.1.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae \Documents\WindowsPowerShell\Modules\PnP.PowerShell\1.12.0\Framework\Microsoft.Identity.Client.dll

Microsoft.Identity.Client, Version=4.37.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Microsoft.Identity.Client.4.37.0\net45\Microsoft.Identity.Client.dll

Microsoft.Identity.Client, Version=4.46.2.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae \Documents\WindowsPowerShell\Modules\Az.Accounts\2.10.4\PreloadAssemblies\Microsoft.Identity.Client.dll

Microsoft.Identity.Client.Desktop, Version=4.37.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Microsoft.Identity.Client.Desktop.4.37.0\net461\Microsoft.Identity.Client.Desktop.dll

Microsoft.Identity.Client.Extensions.Msal, Version=2.18.4.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae \Documents\WindowsPowerShell\Modules\PnP.PowerShell\1.12.0\Framework\Microsoft.Identity.Client.Extensions.Msal.dll

Microsoft.Identity.Client.Extensions.Msal, Version=2.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae \Documents\WindowsPowerShell\Modules\Az.Accounts\2.10.4\PreloadAssemblies\Microsoft.Identity.Client.Extensions.Msal.dll

Microsoft.IdentityModel.Abstractions, Version=6.22.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 \Documents\WindowsPowerShell\Modules\Az.Accounts\2.10.4\PreloadAssemblies\Microsoft.IdentityModel.Abstractions.dll

Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.19.7.16602, Culture=neutral, PublicKeyToken=31bf3856ad364e35 \Documents\WindowsPowerShell\Modules\AzureADPreview\2.0.2.149\Microsoft.IdentityModel.Clients.ActiveDirectory.dll

dingmeng-xue commented 1 year ago

@mark3grahams , please import-module az.accounts at the beginning of your script.

mark3grahams commented 1 year ago

Is this a bug or something I am doing wrong?

dingmeng-xue commented 1 year ago

No. it is a limitation of .NET and PowerShell so far. If one assembly is loaded into .NET runtime, it may interfere others which are depending on the same assembly but different version.

Is this a bug or something I am doing wrong?

ghost commented 1 year ago

Hi @mark3grahams. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.

mark3grahams commented 1 year ago

/unresolve.

I've done that and it did not seem to help.

Requires -Module ActiveDirectory,Az.Accounts,ImportExcel

# Importing the required modules $Modules = @' ActiveDirectory Az.Accounts ImportExcel '@ -split "`n" | ForEach-Object { $.trim() } $Modules | ForEach-Object { Import-Module -Name $\ -Force -ErrorAction Stop }

mark3grahams commented 1 year ago

FullName Location Azure.Identity, Version=1.6.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8 \Documents\WindowsPowerShell\Modules\Az.Accounts\2.10.4\PreloadAssemblies\Azure.Identity.dll

Microsoft.Identity.Client, Version=4.36.1.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae \Documents\WindowsPowerShell\Modules\PnP.PowerShell\1.12.0\Framework\Microsoft.Identity.Client.dll

Microsoft.Identity.Client, Version=4.46.2.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae \Documents\WindowsPowerShell\Modules\Az.Accounts\2.10.4\PreloadAssemblies\Microsoft.Identity.Client.dll

Microsoft.Identity.Client.Extensions.Msal, Version=2.18.4.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae \Documents\WindowsPowerShell\Modules\PnP.PowerShell\1.12.0\Framework\Microsoft.Identity.Client.Extensions.Msal.dll

Microsoft.Identity.Client.Extensions.Msal, Version=2.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae \Documents\WindowsPowerShell\Modules\Az.Accounts\2.10.4\PreloadAssemblies\Microsoft.Identity.Client.Extensions.Msal.dll

Microsoft.IdentityModel.Abstractions, Version=6.22.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 \Documents\WindowsPowerShell\Modules\Az.Accounts\2.10.4\PreloadAssemblies\Microsoft.IdentityModel.Abstractions.dll

dingmeng-xue commented 1 year ago

@mark3grahams , what's the result if you only import Az.Accounts and execute Connect-AzAccount?

mark3grahams commented 1 year ago

The error has been hit or miss, but I’ll give this a try a few times today and report back.

mark3grahams commented 1 year ago

Import-Module Az.Accounts

connect-azAccount

That seemed fine as it logged on with my user and not the certificate.

mark3grahams commented 1 year ago

Do you have any other suggestions?

mark3grahams commented 1 year ago

/unresolve

mark3grahams commented 1 year ago

This is not resolved.

mark3grahams commented 9 months ago

Still not resolved.

BrianL-STCU commented 9 months ago

This module seems to be incompatible with dbatools.

BrianL-STCU commented 9 months ago

Correction: Importing Az.Accounts before dbatools (in $Profile, perhaps) seems to work.