SQLServerPSModule icon indicating copy to clipboard operation
SQLServerPSModule copied to clipboard

invoke-Sqlcmd : Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder

Open pradeep14316 opened this issue 1 year ago • 1 comments

Haven't started on reproducing outside of Azure Pipelines yet, but: Copied from the issue in Description SqlServer 22.0.59 / Windows PowerShell 5.1 / windows-latest/ Azure DevOps

This occurs on Microsoft-hosted agents.

When attempting to connect to a Azure SQL Databases with Active Directory Password authentication, this occurs:

with the following connection string characteristics: MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication="Active Directory Password";

2024-07-16T13:14:17.1472821Z ##[debug]Invoke-Sqlcmd : Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Identity.Client.PublicClientApplicationBuilder.WithParentActivityOrWindow(System.Func1<System.Windows.Forms.IWin32Window>)'. 2024-07-16T13:14:17.1485055Z ##[debug]At D:\a\_temp\1ded7a10-b4d6-402d-8b7a-38aa2208e1c4.ps1:54 char:1 2024-07-16T13:14:17.1498800Z ##[debug]+ Invoke-Sqlcmd -Query "$SCHEMAQuery" -ConnectionString "Server=tcp:azr ... 2024-07-16T13:14:17.1510324Z ##[debug]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2024-07-16T13:14:17.1523235Z ##[debug] + CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], SqlException 2024-07-16T13:14:17.1534509Z ##[debug] + FullyQualifiedErrorId : SqlExceptionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand 2024-07-16T13:14:17.1546662Z ##[debug] 2024-07-16T13:14:17.1564682Z ##[debug]Script stack trace: 2024-07-16T13:14:17.1598572Z ##[debug]at <ScriptBlock>, D:\a\_temp\1ded7a10-b4d6-402d-8b7a-38aa2208e1c4.ps1: line 54 2024-07-16T13:14:17.1609725Z ##[debug]at <ScriptBlock>, D:\a\_temp\1ded7a10-b4d6-402d-8b7a-38aa2208e1c4.ps1: line 52 2024-07-16T13:14:17.1621003Z ##[debug]at <ScriptBlock>, <No file>: line 1 2024-07-16T13:14:17.1638556Z ##[debug]Exception: 2024-07-16T13:14:17.2213587Z ##[debug]Microsoft.Data.SqlClient.SqlException (0x80131904): Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Identity.Client.PublicClientApplicationBuilder.WithParentActivityOrWindow(System.Func1<System.Windows.Forms.IWin32Window>)'. ---> System.MissingMethodException: Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Identity.Client.PublicClientApplicationBuilder.WithParentActivityOrWindow(System.Func1<System.Windows.Forms.IWin32Window>)'. 2024-07-16T13:14:17.2227297Z ##[debug] at Microsoft.Data.SqlClient.ActiveDirectoryAuthenticationProvider.CreateClientAppInstance(PublicClientAppKey publicClientAppKey) 2024-07-16T13:14:17.2240879Z ##[debug] at Microsoft.Data.SqlClient.ActiveDirectoryAuthenticationProvider.GetPublicClientAppInstance(PublicClientAppKey publicClientAppKey) 2024-07-16T13:14:17.2253692Z ##[debug] at Microsoft.Data.SqlClient.ActiveDirectoryAuthenticationProvider.<AcquireTokenAsync>d__21.MoveNext() 2024-07-16T13:14:17.2266251Z ##[debug]--- End of stack trace from previous location where exception was thrown --- 2024-07-16T13:14:17.2278401Z ##[debug] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 2024-07-16T13:14:17.2289859Z ##[debug] at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 2024-07-16T13:14:17.2301125Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.<>c__DisplayClass159_1.<<GetFedAuthToken>b__3>d.MoveNext() 2024-07-16T13:14:17.2312170Z ##[debug]--- End of stack trace from previous location where exception was thrown --- 2024-07-16T13:14:17.2323421Z ##[debug] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 2024-07-16T13:14:17.2334444Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.GetFedAuthToken(SqlFedAuthInfo fedAuthInfo) 2024-07-16T13:14:17.2345596Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.GetFedAuthToken(SqlFedAuthInfo fedAuthInfo) 2024-07-16T13:14:17.2356604Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo) 2024-07-16T13:14:17.2367914Z ##[debug] at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) 2024-07-16T13:14:17.2379114Z ##[debug] at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 2024-07-16T13:14:17.2390099Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) 2024-07-16T13:14:17.2401214Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover, Boolean isFirstTransparentAttempt, Boolean disableTnir) 2024-07-16T13:14:17.2412520Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) 2024-07-16T13:14:17.2423532Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) 2024-07-16T13:14:17.2435199Z ##[debug] at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, ServerCertificateValidationCallback serverCallback, ClientCertificateRetrievalCallback clientCallback, DbConnectionPool pool, String accessToken, SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo, Boolean applyTransientFaultHandling) 2024-07-16T13:14:17.2445782Z ##[debug] at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) 2024-07-16T13:14:17.2457167Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) 2024-07-16T13:14:17.2468002Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) 2024-07-16T13:14:17.2479137Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) 2024-07-16T13:14:17.2490177Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) 2024-07-16T13:14:17.2501432Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) 2024-07-16T13:14:17.2512612Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) 2024-07-16T13:14:17.2523755Z ##[debug] at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) 2024-07-16T13:14:17.2534590Z ##[debug] at Microsoft.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) 2024-07-16T13:14:17.2545970Z ##[debug] at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry, SqlConnectionOverrides overrides) 2024-07-16T13:14:17.2556865Z ##[debug] at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides) 2024-07-16T13:14:17.2567976Z ##[debug] at Microsoft.SqlServer.Management.PowerShell.ExecutionProcessor.ExecuteBatch(String batch) 2024-07-16T13:14:17.2578956Z ##[debug] at Microsoft.SqlServer.Management.PowerShell.ExecutionProcessor.ProcessBatch(String str, Int32 num) 2024-07-16T13:14:17.2672372Z ##[error]Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Identity.Client.PublicClientApplicationBuilder.WithParentActivityOrWindow(System.Func1<System.Windows.Forms.IWin32Window>)'. 2024-07-16T13:14:17.2673635Z ##[debug]Processed: ##vso[task.logissue source=TaskInternal;type=error]Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Identity.Client.PublicClientApplicationBuilder.WithParentActivityOrWindow(System.Func1<System.Windows.Forms.IWin32Window>)'. 2024-07-16T13:14:17.3068582Z ##[debug]Exit code: 1 2024-07-16T13:14:17.3106125Z ##[debug]Leaving Invoke-VstsTool. 2024-07-16T13:14:17.3704800Z ##[error]PowerShell exited with code '1'. 2024-07-16T13:14:17.3705621Z ##[debug]Processed: ##vso[task.logissue source=TaskInternal;type=error]PowerShell exited with code '1'. 2024-07-16T13:14:17.3774197Z ##[debug]Processed: ##vso[task.complete result=Failed]Error detected 2024-07-16T13:14:17.3846711Z ##[debug]Loading module from path 'D:\a_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.242.0\ps_modules\VstsAzureHelpers_\VstsAzureHelpers_.psm1'. 2024-07-16T13:14:17.3978576Z ##[debug]$OVERRIDING $global:DebugPreference from 'Continue' to 'SilentlyContinue'. 2024-07-16T13:14:17.4005738Z ##[debug]Loading resource strings from: D:\a_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.242.0\ps_modules\VstsAzureHelpers_/module.json 2024-07-16T13:14:17.4371588Z ##[debug]Loaded 19 strings. 2024-07-16T13:14:17.4403007Z ##[debug]SYSTEM_CULTURE: 'en-US' 2024-07-16T13:14:17.4426060Z ##[debug]Loading resource strings from: D:\a_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.242.0\ps_modules\VstsAzureHelpers_\Strings\resources.resjson\en-US\resources.resjson 2024-07-16T13:14:17.4798357Z ##[debug]Loaded 19 strings.

pradeep14316 avatar Jul 18 '24 13:07 pradeep14316

having the same issue, did you find any solution?

DesiStuff avatar Jul 29 '24 09:07 DesiStuff

I don't know how to repro this problem, so I'm going to ask you guys to check it in the upcoming v22.4 and let me know whether the issue went away or not.

Matteo-T avatar Jun 14 '25 16:06 Matteo-T

This was fixed in 22.4.5.1

Matteo-T avatar Jun 17 '25 10:06 Matteo-T

I hadn’t encountered this issue before, but starting roughly two hours ago, the SQL script Azure SQL Database deployment steps began failing in my Azure DevOps pipelines with the following error:

2025-06-17T13:14:39.6437017Z ##[error]Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Identity.Client.PublicClientApplicationBuilder.WithParentActivityOrWindow(System.Func`1<System.Windows.Forms.IWin32Window>)'.Check out how to troubleshoot failures at https://aka.ms/sqlazuredeployreadme#troubleshooting-

I searched for the error online, which led me here. I’m not certain if it’s related, but the timing feels like a weird coincidence.

edit: I added an extra pipeline step that removes 22.4.5.1 and installs 22.3.0 and the error went away.

gmolnar-at-am avatar Jun 17 '25 13:06 gmolnar-at-am

Hello @gergo-molnar-at-abacus-medicine I appreciate your update. When you say that you added an extra pipeline step that removes 22.4.5.1 and installs 22.3.0 and the error went away.

What software version are you modifying there? the one of the NET API browser?

I ask this because I am kind of rookie on this.

Thanks in advance.

RufusTK avatar Jun 19 '25 15:06 RufusTK

I can confirm that reverting to 22.3.0 fixed this for me (thanks @gergo-molnar-at-abacus-medicine )

@RufusTK I added two Powershell Scripts (inline)

Uninstall-Module -Name SqlServer -AllVersions

and

Install-Module -Name SqlServer -RequiredVersion 22.3.0 -Force -AllowClobber

Dave-Osborne avatar Jun 23 '25 08:06 Dave-Osborne

@RufusTK I use an Azure DevOps pipeline to deploy to our application to environments in Azure. These pipelines run on agents — which, ultimately, are just machines with some pre-installed software. What I do is pretty much the same as what @Dave-Osborne described.

gmolnar-at-am avatar Jun 23 '25 11:06 gmolnar-at-am

My pipelines are also having the same issue, is there a permanent fix for this issue in the pipelines?

PedroC88 avatar Jul 10 '25 16:07 PedroC88

@Dave-Osborne

  • are you using Microsoft Hosted Agents?
  • are you using a SQL Login or an Entra account?

I haven't been able to figure this out and most of my pipelines are broken. When I try to uninstall the module, I get an error that SqlServer is not installed, even though Invoke-SqlCmd is coming from a SqlServer module it seems to be from on-memory, and even when I successfully install 22.3.0, the installed version doesn't carry over to the next task.

Also, even if I tried to use invoke-sqlcmd directly on PS after importing the module, the downloaded module doesn't support the Authentication parameter to use ActiveDirectoryPassword with an Entra account.

I think this ticket needs to be reopened, because the issue that is being reported broke WITH 22.4.5 and wasn't an issue before.

PedroC88 avatar Jul 13 '25 23:07 PedroC88

This is still a bug - running MS hosted agents Win2025 - using AD with Password. SQL Dacpac deployment in yml pipeline to run simple scripts. I used the recommended work-around above by downgrading SQLServer Powershell tools to get it working.

keithmitworks avatar Sep 08 '25 14:09 keithmitworks

Interestingly, I hadn’t run into the issue described in this ticket until version 22.4.5.1 of the module was released. That was the version that claimed to fix it, and that’s actually when the issue started appearing for me.

This ticket was marked as fixed and closed at that time, so I opened a new ticket back in June 2025 when I first encountered the issue, hoping it would get more attention than a closed one. https://github.com/microsoft/SQLServerPSModule/issues/108

The common factor is the error message: Method not found: Microsoft.Identity.Client.PublicClientApplicationBuilder...

gmolnar-at-am avatar Sep 08 '25 14:09 gmolnar-at-am