Skip to content

Connect-AzAccount works through powershell but not when called by C# application running in VS2022 #27374

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

Open
taylorcode216 opened this issue Mar 18, 2025 · 5 comments
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Possible-Solution Similar-Issue

Comments

@taylorcode216
Copy link

taylorcode216 commented Mar 18, 2025

Description

I have a windows forms application that we migrated to .NET 9 so that Microsoft.Powershell.SDK will run Powershell 7 instead of Powershell 5 due to issues we were facing with Connect-AzAccount in PowerShell 5. From Powershell 7, I can run Connect-AzAccount with no issue, but when I execute the command vai a PowerShell object in C#, the interactive browser login does not open, and I get a Method not found error for Azure.Identity,InteractiveBrowserCredential.AuthenticateAsync.

I have tried disabling WAM, turning off the V2 Login Experience and connecting using a service account:

#Update-AzConfig -EnableLoginByWam $false
#Update-AzConfig -LoginExperienceV2 Off

Connecting using a service account - this returned an "Entry point not found" error and seems to be using a different API call than when I run it directly in Powershell v7

  • From C#
Request [413f8576-e5b0-453a-aa24-88428e8b4475] GET https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=REDACTED
x-client-SKU:REDACTED
x-client-Ver:REDACTED
x-client-OS:REDACTED
client-request-id:REDACTED
return-client-request-id:REDACTED
x-ms-client-request-id:413f8576-e5b0-453a-aa24-88428e8b4475
x-ms-return-client-request-id:true
User-Agent:azsdk-net-Identity/1.13.0 (.NET 9.0.3; Microsoft Windows 10.0.14393)
client assembly: Azure.Identity"
  • From Powershell
Request [32df3b28-8fc5-4651-81cc-23acb0231378] POST https://login.microsoftonline.com/zzzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzzz/oauth2/v2.0/token 
x-client-SKU:REDACTED
x-client-Ver:REDACTED
x-client-OS:REDACTED
x-client-current-telemetry:REDACTED
x-ms-PKeyAuth:REDACTED
x-ms-lib-capability:REDACTED
client-request-id:REDACTED
return-client-request-id:REDACTED
Content-Type:application/x-www-form-urlencoded
x-ms-client-request-id:32df3b28-8fc5-4651-81cc-23acb0231378
x-ms-return-client-request-id:true
User-Agent:azsdk-net-Identity/1.13.0 (.NET 9.0.1; Microsoft Windows 10.0.14393)
client assembly: Azure.Identity

Issue script & Debug output

$DebugPreference = 'Continue'
Clear-AzContext -Force
Connect-AzAccount

DebugRecord.Message
Initializing ConditionalAssemblyContext. PSEdition is [Core]. PSVersion is [7.5.0].
Initializing ConditionalAssemblyProvider. AssemblyRootPath is [C:\Users\user\Documents\PowerShell\Modules\Az.Accounts\4.0.2\StartupScripts\..\lib].
Registering Az shared AssemblyLoadContext.
AssemblyLoadContext registered.
Initializing PSStyle.
1:04:27 PM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning default value [True].
1:04:27 PM - ClearAzureRmContext begin processing with ParameterSet '__AllParameterSets'.
1:04:27 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [Az.Accounts], Cmdlet = [Clear-AzContext]. Returning default value [True].
1:04:27 PM - Autosave setting from startup session: 'CurrentUser'
1:04:27 PM - No autosave setting detected in environment variable 'AzContextAutoSave'. 
1:04:27 PM - Using Autosave scope 'CurrentUser'
1:04:27 PM - Autosave setting from startup session: 'CurrentUser'
1:04:27 PM - No autosave setting detected in environment variable 'AzContextAutoSave'. 
1:04:27 PM - Using Autosave scope 'CurrentUser'
1:04:27 PM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
1:04:27 PM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
AzureQoSEvent:  Module: Az.Accounts:4.0.2; CommandName: Clear-AzContext; PSVersion: 7.5.0; IsSuccess: True; Duration: 00:00:00.0223064; SanitizeDuration: 00:00:00
1:04:27 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
1:04:27 PM - ClearAzureRmContext end processing.
1:04:27 PM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning default value [True].
1:04:27 PM - ConnectAzureRmAccountCommand begin processing with ParameterSet 'UserWithSubscriptionId'.
1:04:27 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [Az.Accounts], Cmdlet = [Connect-AzAccount]. Returning default value [True].
1:04:27 PM - [ConfigManager] Got nothing from [DefaultSubscriptionForLogin], Module = [], Cmdlet = []. Returning default value [].
1:04:27 PM - Autosave setting from startup session: 'CurrentUser'
1:04:27 PM - No autosave setting detected in environment variable 'AzContextAutoSave'. 
1:04:27 PM - Using Autosave scope 'CurrentUser'
"1:04:27 PM - Unable to acquire token for tenant 'organizations' with error 'System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task`1<Azure.Identity.AuthenticationRecord> Azure.Identity.InteractiveBrowserCredential.AuthenticateAsync(Azure.Core.TokenRequestContext, System.Threading.CancellationToken)'.
   at Microsoft.Azure.PowerShell.Authenticators.InteractiveWamAuthenticator.Authenticate(AuthenticationParameters parameters, CancellationToken cancellationToken)
   at Microsoft.Azure.Commands.Common.Authentication.DelegatingAuthenticator.TryAuthenticate(AuthenticationParameters parameters, CancellationToken cancellationToken, Task`1& token)
   at Microsoft.Azure.Commands.Common.Authentication.DelegatingAuthenticator.TryAuthenticate(AuthenticationParameters parameters, Task`1& token)
   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.ListAccountTenants(IAzureAccount account, IAzureEnvironment environment, SecureString password, String promptBehavior, Action`1 promptAction)'"
1:04:27 PM - [ConfigManager] Got nothing from [EnableErrorRecordsPersistence], Module = [Az.Accounts], Cmdlet = [Connect-AzAccount]. Returning default value [False].
1:04:27 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [Az.Accounts], Cmdlet = [Connect-AzAccount]. Returning default value [True].
1:04:27 PM - [ConfigManager] Got nothing from [LoginExperienceV2], Module = [], Cmdlet = []. Returning default value [On].
1:04:27 PM - [ConfigManager] Got [True] from [EnableLoginByWam], Module = [], Cmdlet = [].
1:04:27 PM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
1:04:27 PM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
AzureQoSEvent:  Module: Az.Accounts:4.0.2; CommandName: Connect-AzAccount; PSVersion: 7.5.0; IsSuccess: False; Duration: 00:00:00.0053855; SanitizeDuration: 00:00:00; Exception: Method not found: 'System.Threading.Tasks.Task`1<Azure.Identity.AuthenticationRecord> Azure.Identity.InteractiveBrowserCredential.AuthenticateAsync(Azure.Core.TokenRequestContext, System.Threading.CancellationToken)'.;
1:04:27 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
1:04:27 PM - ConnectAzureRmAccountCommand end processing.

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
OS                             Microsoft Windows 10.0.14393
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     4.0.2                 Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzConte…

PS C:\Windows\System32> get-Module -ListAvailable | Where-Object {$_.Name -like "Az*"}

    Directory: C:\Users\user\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     13.3.0                Az                                  Core,Desk
Script     4.0.2                 Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzCo…
Script     4.0.0                 Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzCo…

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     2.1.0                 Az.Advisor                          Core,Desk {Disable-AzAdvisorRecommendation, Enabl…
Script     6.1.0                 Az.Aks                              Core,Desk {Disable-AzAksAddOn, Enable-AzAksAddOn,…
Script     1.2.0                 Az.AnalysisServices                 Core,Desk {Add-AzAnalysisServicesAccount, Export-…
Script     4.1.0                 Az.ApiManagement                    Core,Desk {Add-AzApiManagementApiToGateway, Add-A…
Script     2.0.1                 Az.App                              Core,Desk {Disable-AzContainerAppRevision, Enable…
Script     1.4.0                 Az.AppConfiguration                 Core,Desk {Clear-AzAppConfigurationDeletedStore, …
Script     2.3.0                 Az.ApplicationInsights              Core,Desk {Get-AzApplicationInsights, Get-AzAppli…
Script     1.1.0                 Az.ArcResourceBridge                Core,Desk {Get-AzArcResourceBridge, Get-AzArcReso…
Script     2.1.0                 Az.Attestation                      Core,Desk {Add-AzAttestationPolicySigner, Get-AzA…
Script     1.1.0                 Az.Automanage                       Core,Desk {Get-AzAutomanageBestPractice, Get-AzAu…
Script     1.11.1                Az.Automation                       Core,Desk {Export-AzAutomationDscConfiguration, E…
Script     3.7.0                 Az.Batch                            Core,Desk {Disable-AzBatchAutoScale, Disable-AzBa…
Script     2.2.0                 Az.Billing                          Core,Desk {Get-AzBillingAccount, Get-AzBillingInv…
Script     3.3.0                 Az.Cdn                              Core,Desk {Clear-AzCdnEndpointContent, Clear-AzFr…
Script     2.1.0                 Az.CloudService                     Core,Desk {Get-AzCloudService, Get-AzCloudService…
Script     1.15.0                Az.CognitiveServices                Core,Desk {Add-AzCognitiveServicesAccountNetworkR…
Script     9.1.0                 Az.Compute                          Core,Desk {Add-AzImageDataDisk, Add-AzVhd, Add-Az…
Script     1.1.0                 Az.ConfidentialLedger               Core,Desk {Get-AzConfidentialLedger, New-AzConfid…
Script     1.1.1                 Az.ConnectedMachine                 Core,Desk {Connect-AzConnectedMachine, Get-AzConn…
Script     4.1.1                 Az.ContainerInstance                Core,Desk {Add-AzContainerInstanceOutput, Get-AzC…
Script     4.3.0                 Az.ContainerRegistry                Core,Desk {Connect-AzContainerRegistry, Get-AzCon…
Script     1.17.0                Az.CosmosDB                         Core,Desk {Get-AzCosmosDBAccount, Get-AzCosmosDBA…
Script     1.2.1                 Az.DataBoxEdge                      Core,Desk {Get-AzDataBoxEdgeBandwidthSchedule, Ge…
Script     1.10.0                Az.Databricks                       Core,Desk {Get-AzDatabricksAccessConnector, Get-A…
Script     1.19.1                Az.DataFactory                      Core,Desk {Add-AzDataFactoryV2DataFlowDebugSessio…
Script     1.1.0                 Az.DataLakeAnalytics                Core,Desk {Add-AzDataLakeAnalyticsDataSource, Add…
Script     1.4.0                 Az.DataLakeStore                    Core,Desk {Add-AzDataLakeStoreFirewallRule, Add-A…
Script     2.6.1                 Az.DataProtection                   Core,Desk {Backup-AzDataProtectionBackupInstanceA…
Script     1.1.1                 Az.DataShare                        Core,Desk {Get-AzDataShare, Get-AzDataShareAccoun…
Script     5.4.1                 Az.DesktopVirtualization            Core,Desk {Disconnect-AzWvdUserSession, Expand-Az…
Script     2.0.1                 Az.DevCenter                        Core,Desk {Connect-AzDevCenterAdminCatalog, Conne…
Script     1.1.0                 Az.DevTestLabs                      Core,Desk {Get-AzDtlAllowedVMSizesPolicy, Get-AzD…
Script     1.3.1                 Az.Dns                              Core,Desk {Add-AzDnsRecordConfig, Get-AzDnsRecord…
Script     1.1.1                 Az.DnsResolver                      Core,Desk {Get-AzDnsForwardingRuleset, Get-AzDnsF…
Script     1.2.1                 Az.ElasticSan                       Core,Desk {Add-AzElasticSanVolumeGroupNetworkRule…
Script     2.2.0                 Az.EventGrid                        Core,Desk {Disable-AzEventGridPartnerTopic, Enabl…
Script     5.2.0                 Az.EventHub                         Core,Desk {New-AzEventHubAuthorizationRuleSASToke…
Script     1.12.0                Az.FrontDoor                        Core,Desk {Disable-AzFrontDoorCustomDomainHttps, …
Script     4.2.0                 Az.Functions                        Core,Desk {Get-AzFunctionApp, Get-AzFunctionAppAv…
Script     6.3.1                 Az.HDInsight                        Core,Desk {Add-AzHDInsightClusterIdentity, Add-Az…
Script     2.1.0                 Az.HealthcareApis                   Core,Desk {Get-AzHealthcareApisService, Get-AzHea…
Script     1.0.0                 Az.HealthDataAIServices             Core,Desk {Get-AzDeidService, New-AzDeidService, …
Script     2.8.0                 Az.IotHub                           Core,Desk {Add-AzIotHubCertificate, Add-AzIotHubC…
Script     6.3.1                 Az.KeyVault                         Core,Desk {Add-AzKeyVaultCertificate, Add-AzKeyVa…
Script     2.4.0                 Az.Kusto                            Core,Desk {Add-AzKustoClusterCalloutPolicy, Add-A…
Script     1.1.0                 Az.LoadTesting                      Core,Desk {Get-AzLoad, New-AzLoad, Remove-AzLoad,…
Script     1.6.0                 Az.LogicApp                         Core,Desk {Get-AzIntegrationAccount, Get-AzIntegr…
Script     1.2.0                 Az.MachineLearning                  Core,Desk {Add-AzMlWebServiceRegionalProperty, Ex…
Script     1.2.0                 Az.MachineLearningServices          Core,Desk {Get-AzMLServiceQuota, Get-AzMLServiceU…
Script     1.5.1                 Az.Maintenance                      Core,Desk {Get-AzApplyUpdate, Get-AzConfiguration…
Script     1.3.0                 Az.ManagedServiceIdentity           Core,Desk {Get-AzFederatedIdentityCredential, Get…
Script     3.1.0                 Az.ManagedServices                  Core,Desk {Get-AzManagedServicesAssignment, Get-A…
Script     2.1.0                 Az.MarketplaceOrdering              Core,Desk {Get-AzMarketplaceTerms, Invoke-AzMarke…
Script     1.2.0                 Az.Media                            Core,Desk {Get-AzMediaService, Get-AzMediaService…
Script     2.7.0                 Az.Migrate                          Core,Desk {Get-AzMigrateDiscoveredServer, Get-AzM…
Script     6.0.1                 Az.Monitor                          Core,Desk {Add-AzLogProfile, Add-AzMetricAlertRul…
Script     1.3.0                 Az.MySql                            Core,Desk {Get-AzMySqlConfiguration, Get-AzMySqlC…
Script     7.14.0                Az.Network                          Core,Desk {Add-AzApplicationGatewayAuthentication…
Script     1.1.0                 Az.NetworkCloud                     Core,Desk {Deploy-AzNetworkCloudCluster, Disable-…
Script     1.2.0                 Az.Nginx                            Core,Desk {Get-AzNginxCertificate, Get-AzNginxCon…
Script     1.2.0                 Az.NotificationHubs                 Core,Desk {Get-AzNotificationHub, Get-AzNotificat…
Script     3.3.0                 Az.OperationalInsights              Core,Desk {Disable-AzOperationalInsightsIISLogCol…
Script     1.1.0                 Az.Oracle                           Core,Desk {Add-AzOracleCloudVMClusterVM, Get-AzOr…
Script     1.7.1                 Az.PolicyInsights                   Core,Desk {Get-AzPolicyAttestation, Get-AzPolicyE…
Script     1.2.0                 Az.PostgreSql                       Core,Desk {Get-AzPostgreSqlConfiguration, Get-AzP…
Script     2.1.0                 Az.PowerBIEmbedded                  Core,Desk {Get-AzPowerBIEmbeddedCapacity, New-AzP…
Script     1.2.0                 Az.PrivateDns                       Core,Desk {Add-AzPrivateDnsRecordConfig, Get-AzPr…
Script     7.5.1                 Az.RecoveryServices                 Core,Desk {Add-AzRecoveryServicesAsrReplicationPr…
Script     1.11.0                Az.RedisCache                       Core,Desk {Export-AzRedisCache, Get-AzRedisCache,…
Script     1.4.1                 Az.RedisEnterpriseCache             Core,Desk {Export-AzRedisEnterpriseCache, Get-AzR…
Script     2.1.0                 Az.Relay                            Core,Desk {Get-AzRelayAuthorizationRule, Get-AzRe…
Script     1.2.0                 Az.ResourceGraph                    Core,Desk {Search-AzGraph, Get-AzResourceGraphQue…
Script     1.3.0                 Az.ResourceMover                    Core,Desk {Add-AzResourceMoverMoveResource, Get-A…
Script     7.9.0                 Az.Resources                        Core,Desk {Export-AzResourceGroup, Export-AzTempl…
Script     1.8.0                 Az.Security                         Core,Desk {Add-AzSecurityAdaptiveNetworkHardening…
Script     3.2.0                 Az.SecurityInsights                 Core,Desk {Get-AzSentinelAlertRule, Get-AzSentine…
Script     4.1.1                 Az.ServiceBus                       Core,Desk {New-AzServiceBusAuthorizationRuleSASTo…
Script     3.5.0                 Az.ServiceFabric                    Core,Desk {Add-AzServiceFabricClientCertificate, …
Script     2.1.0                 Az.SignalR                          Core,Desk {Get-AzSignalR, Get-AzSignalRKey, Get-A…
Script     6.0.2                 Az.Sql                              Core,Desk {Add-AzSqlDatabaseToFailoverGroup, Add-…
Script     2.4.0                 Az.SqlVirtualMachine                Core,Desk {Assert-AzSqlVMEntraAuth, Get-AzAvailab…
Script     2.5.0                 Az.StackHCI                         Core,Desk {Add-AzStackHCIVMAttestation, Disable-A…
Script     1.1.0                 Az.StackHCIVM                       Core,Desk {Add-AzStackHCIVMVirtualMachineDataDisk…
Script     8.2.0                 Az.Storage                          Core,Desk {Add-AzRmStorageContainerLegalHold, Add…
Script     1.5.0                 Az.StorageMover                     Core,Desk {Get-AzStorageMover, Get-AzStorageMover…
Script     2.4.1                 Az.StorageSync                      Core,Desk {Get-AzStorageSyncCloudEndpoint, Get-Az…
Script     2.1.0                 Az.StreamAnalytics                  Core,Desk {Get-AzStreamAnalyticsCluster, Get-AzSt…
Script     2.1.0                 Az.Support                          Core,Desk {Get-AzSupportChatTranscript, Get-AzSup…
Script     3.1.2                 Az.Synapse                          Core,Desk {Add-AzSynapseDataFlowDebugSessionPacka…
Script     1.3.0                 Az.TrafficManager                   Core,Desk {Add-AzTrafficManagerCustomHeaderToEndp…
Script     3.3.1                 Az.Websites                         Core,Desk {Add-AzWebAppAccessRestrictionRule, Add…
Script     1.0.0                 Az.Workloads                        Core,Desk {Get-AzWorkloadsMonitor, Get-AzWorkload…
Script     4.2.1                 Azure.Storage                       Desk      {Get-AzureStorageTable, New-AzureStorag

Error output

Method not found: 'System.Threading.Tasks.Task`1<Azure.Identity.AuthenticationRecord> Azure.Identity.InteractiveBrowserCredential.AuthenticateAsync(Azure.Core.TokenRequestContext, System.Threading.CancellationToken)'.
   at Microsoft.Azure.PowerShell.Authenticators.InteractiveWamAuthenticator.Authenticate(AuthenticationParameters parameters, CancellationToken cancellationToken)
   at Microsoft.Azure.Commands.Common.Authentication.DelegatingAuthenticator.TryAuthenticate(AuthenticationParameters parameters, CancellationToken cancellationToken, Task`1& token)
   at Microsoft.Azure.Commands.Common.Authentication.DelegatingAuthenticator.TryAuthenticate(AuthenticationParameters parameters, Task`1& token)
   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.ListAccountTenants(IAzureAccount account, IAzureEnvironment environment, SecureString password, String promptBehavior, Action`1 promptAction)
   at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.Login(IAzureAccount account, IAzureEnvironment environment, String tenantIdOrName, String subscriptionId, String subscriptionName, SecureString password, Boolean skipValidation, IOpenIDConfiguration openIDConfigDoc, Action`1 promptAction, String name, Boolean shouldPopulateContextList, Int32 maxContextPopulation, String authScope, Boolean IsInteractiveContextSelectionEnabled)
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass134_2.<ExecuteCmdlet>b__7()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass134_1.<ExecuteCmdlet>b__1(AzureRmProfile localProfile, RMProfileClient profileClient, String name)
   at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass150_0.<SetContextWithOverwritePrompt>b__0(AzureRmProfile prof, RMProfileClient client)
   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.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
@taylorcode216 taylorcode216 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 Mar 18, 2025
@taylorcode216 taylorcode216 changed the title AzConnect works through powershell but not when called by C# application running in VS2022 Connect-AzAccount works through powershell but not when called by C# application running in VS2022 Mar 18, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Mar 18, 2025
Copy link

Here are some similar issues that might help you. Please check if they can solve your problem.


Possible solution (Extracted from existing issue, might be incorrect; please verify carefully)

We are sharing an engineering build of Az.Accounts 2.6.2 https://azposhpreview.blob.core.windows.net/public/Az.Accounts.2.6.2.nupkg.

Please download and install it following instruction.

Register-PSRepository -Name LocalPSRepo -SourceLocation ' C:\Dev\testrepo' -ScriptSourceLocation ' C:\Dev\testrepo' -InstallationPolicy Trusted
  • Install Az.Accounts module from local repository.
* Install-Module Az.Accounts -Repository LocalPSRepo

Please let us know whether issue can be eliminated. Your feedback is very important to us.

Reference:

Powered by issue-sentinel

Copy link

Here are some similar issues that might help you. Please check if they can solve your problem.


Possible solution (Extracted from existing issue, might be incorrect; please verify carefully)

Solution 1:

We are sharing an engineering build of Az.Accounts 2.6.2 https://azposhpreview.blob.core.windows.net/public/Az.Accounts.2.6.2.nupkg.

Please download and install it following instruction.

Register-PSRepository -Name LocalPSRepo -SourceLocation ' C:\Dev\testrepo' -ScriptSourceLocation ' C:\Dev\testrepo' -InstallationPolicy Trusted
  • Install Az.Accounts module from local repository.
* Install-Module Az.Accounts -Repository LocalPSRepo

Please let us know whether issue can be eliminated. Your feedback is very important to us.

Reference:

Solution 2:

Az.Accounts 2.6.2 fixed the issue for me - I can successfully use Connect-AzAccount inside Visual Studio Code's PowerShell 5.1 Integrated Console using Az 6.6.0 from PSGallery and Az.Accounts 2.6.2 from LocalPSRepo.

Reference:

Solution 3:

I can confirm that that provided engineering build fixed problem on my machine. Thanks!

Reference:

Powered by issue-sentinel

@taylorcode216
Copy link
Author

taylorcode216 commented Mar 18, 2025

These solutions are for Powershell 5 and Az.Accounts 2.6.2. I'm using Powershell 7 and Az.Accounts 4.0.2

@taylorcode216
Copy link
Author

An update on this would be great - the above do not resolve the issue, and this is a current blocker for my team

@MiFask0
Copy link

MiFask0 commented Apr 1, 2025

Bump, encountering the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Possible-Solution Similar-Issue
Projects
None yet
Development

No branches or pull requests

2 participants