Skip to content
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

[BUG]: Azure PowerShell task fails with Exception calling ".ctor" with "3" argument(s): "Method not found: 'Newtonsoft.Json.JsonSerializerSettings System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.get_SerializerSettings()'." #20707

Open
4 of 7 tasks
BNDKPNTR opened this issue Dec 3, 2024 · 3 comments

Comments

@BNDKPNTR
Copy link

BNDKPNTR commented Dec 3, 2024

New issue checklist

Task name

AzurePowerShell

Task version

5

Issue Description

The Azure PowerShell task is failing with the following error: Exception calling ".ctor" with "3" argument(s): "Method not found: 'Newtonsoft.Json.JsonSerializerSettings System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.get_SerializerSettings()'.".

The error happened after I have switched my Azure service connection from service principal (manual) to workload identity federation (manual).

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

Windows

Relevant log output

==============================================================================
Task         : Azure PowerShell
Description  : Run a PowerShell script within an Azure environment
Version      : 5.248.3
Author       : Microsoft Corporation
Help         : https://aka.ms/azurepowershelltroubleshooting
==============================================================================
##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\44a67e4e-e79e-4257-aa1a-cd83110edc30.ps1'"
##[command]Import-Module -Name C:\Modules\az_3.1.0\Az.Accounts\2.2.5\Az.Accounts.psd1 -Global
##[warning]You're using AzureRM which will be retired soon, please schedule an update.
##[debug]Error record:
##[debug]Get-VstsVssHttpClient : Exception calling ".ctor" with "3" argument(s): "Method not found: 'Newtonsoft.Json.JsonSerializerSettings System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.get_SerializerSettings()'."
##[debug]At D:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.248.3\ps_modules\VstsAzureHelpers_\Utility.ps1:234 char:27
##[debug]+ ...   $taskHttpClient = Get-VstsVssHttpClient -OMDirectory $OMDirectory `
##[debug]+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##[debug]    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
##[debug]    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-VstsVssHttpClient
##[debug] 
##[debug]Script stack trace:
##[debug]at Get-VssHttpClient, D:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.248.3\ps_modules\VstsTaskSdk\ServerOMFunctions.ps1: line 486
##[debug]at Get-VstsFederatedToken, D:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.248.3\ps_modules\VstsAzureHelpers_\Utility.ps1: line 234
##[debug]at Initialize-AzSubscription, D:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.248.3\ps_modules\VstsAzureHelpers_\InitializeAzModuleFunctions.ps1: line 378
##[debug]at Initialize-AzModule, D:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.248.3\ps_modules\VstsAzureHelpers_\InitializeAzModuleFunctions.ps1: line 58
##[debug]at <ScriptBlock>, D:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\5.248.3\CoreAz.ps1: line 33
##[debug]at <ScriptBlock>, D:\a\_temp\44a67e4e-e79e-4257-aa1a-cd83110edc30.ps1: line 3
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]Exception:
##[debug]Microsoft.PowerShell.Commands.WriteErrorException: Exception calling ".ctor" with "3" argument(s): "Method not found: 'Newtonsoft.Json.JsonSerializerSettings System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.get_SerializerSettings()'."
##[error]Exception calling ".ctor" with "3" argument(s): "Method not found: 'Newtonsoft.Json.JsonSerializerSettings System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.get_SerializerSettings()'."
##[debug]Processed: ##vso[task.logissue source=TaskInternal;type=error]Exception calling ".ctor" with "3" argument(s): "Method not found: 'Newtonsoft.Json.JsonSerializerSettings System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.get_SerializerSettings()'."
##[debug]Exit code: 1
##[debug]Leaving Invoke-VstsTool.
##[error]PowerShell exited with code '1'.

Full task logs with system.debug enabled

tasklog_9.log

Repro steps

@BNDKPNTR
Copy link
Author

Hi @v-schhabra, I'm not sure where to update the version of Az.Module, because the error is coming from the Azure PowerShell task itself, before reaching my script.

@v-schhabra
Copy link
Contributor

Hi @BNDKPNTR
Please update the Microsoft hosted agent which you are using in the pipeline?

@BNDKPNTR
Copy link
Author

Hi @v-schhabra, I'm using the windows-latest agent, as you can see below:
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants