Skip to content

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

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

Closed
mark3grahams opened this issue Dec 28, 2022 · 20 comments
Labels
customer-reported needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@mark3grahams
Copy link

mark3grahams commented Dec 28, 2022

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.
@mark3grahams mark3grahams added bug This issue requires a change to an existing behavior in the product in order to be resolved. needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Dec 28, 2022
@ghost ghost added customer-reported and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Dec 28, 2022
@dingmeng-xue
Copy link
Member

@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

@dingmeng-xue dingmeng-xue added question The issue doesn't require a change to the product in order to be resolved. Most issues start as that needs-author-feedback More information is needed from author to address the issue. and removed bug This issue requires a change to an existing behavior in the product in order to be resolved. labels Dec 31, 2022
@mark3grahams
Copy link
Author

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

@ghost ghost added needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-author-feedback More information is needed from author to address the issue. labels Dec 31, 2022
@mark3grahams
Copy link
Author

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
Copy link
Member

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

@mark3grahams
Copy link
Author

Is this a bug or something I am doing wrong?

@dingmeng-xue
Copy link
Member

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?

@dingmeng-xue dingmeng-xue added issue-addressed and removed needs-team-attention This issue needs attention from Azure service team or SDK team labels Jan 4, 2023
@ghost
Copy link

ghost commented Jan 4, 2023

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
Copy link
Author

mark3grahams commented Jan 4, 2023

/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 }

@ghost ghost added needs-team-attention This issue needs attention from Azure service team or SDK team and removed issue-addressed labels Jan 4, 2023
@mark3grahams
Copy link
Author

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
Copy link
Member

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

@mark3grahams
Copy link
Author

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

@dingmeng-xue dingmeng-xue added needs-author-feedback More information is needed from author to address the issue. and removed needs-team-attention This issue needs attention from Azure service team or SDK team labels Jan 8, 2023
@mark3grahams
Copy link
Author

Import-Module Az.Accounts

connect-azAccount

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

@ghost ghost added needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-author-feedback More information is needed from author to address the issue. labels Jan 11, 2023
@mark3grahams
Copy link
Author

Do you have any other suggestions?

@mark3grahams
Copy link
Author

/unresolve

@mark3grahams
Copy link
Author

This is not resolved.

@mark3grahams mark3grahams closed this as not planned Won't fix, can't repro, duplicate, stale Sep 29, 2023
@mark3grahams
Copy link
Author

Still not resolved.

@mark3grahams mark3grahams reopened this Oct 13, 2023
@BrianL-STCU
Copy link

This module seems to be incompatible with dbatools.

@BrianL-STCU
Copy link

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

@isra-fel
Copy link
Member

isra-fel commented Jan 2, 2025

The MethodNotFound error indicates there is highly likely an asssembly conflict. General suggestions to these problems are:

  • Switch to powershell 7 from 5
  • Try changing the order of modules being imported
  • Isolate the cmdlets from differernt modules

@isra-fel isra-fel closed this as completed Jan 2, 2025
@mark3grahams
Copy link
Author

mark3grahams commented Jan 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

4 participants