DEV Community

Jesse Houwing for Xebia Microsoft Services

Posted on • Originally published at jessehouwing.net on

VSBuild task fails on self-hosted Azure Pipelines Agent

VSBuild task fails on self-hosted Azure Pipelines Agent

Today I got this baffling error while trying to run one of the few pipelines I own that requires a self-hosted agent.

2023-09-18T13:24:55.1897667Z ##[section]Starting: VSBuild
2023-09-18T13:24:55.2042232Z ==============================================================================
2023-09-18T13:24:55.2042611Z Task : Visual Studio build
2023-09-18T13:24:55.2042705Z Description : Build with MSBuild and set the Visual Studio version property
2023-09-18T13:24:55.2042827Z Version : 1.214.0
2023-09-18T13:24:55.2042907Z Author : Microsoft Corporation
2023-09-18T13:24:55.2042985Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/visual-studio-build
2023-09-18T13:24:55.2043127Z ==============================================================================
2023-09-18T13:24:56.8956825Z ##[error]The following error occurred while loading the extended type data file: Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member AuditToString is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member AccessToString is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Sddl is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Access is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Group is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Owner is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Path is already present.

2023-09-18T13:24:57.0291684Z ##[error]The 'ConvertTo-SecureString' command was found in the module 'Microsoft.PowerShell.Security', but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Security'.
2023-09-18T13:24:57.0552980Z ##[section]Finishing: VSBuild
Enter fullscreen mode Exit fullscreen mode

I don't run this pipeline often and had re-imaged my laptop since the last run in March 2023... And was stumped by the error message. Googling a bit led me to a pretty old GitHub issue which explains the problem might happen in you run a PowerShell script in a PowerShell 5.1 terminal a Windows Command Prompt in a PowerShell Core terminal.

But I wasn't, was I?!

After some more head scratching, I figured it out. I was running my Azure Pipelines agent Interactively and had launched it from a PowerShell 7 terminal. terminating the agent, opening a Windows Command prompt, and relaunching the agent fixed things.

[BUG]: launching self-hosted agent from powershell core prompt causes powershell-based tasks to fail #4438

What happened?

I provisioned a new self-hosted agent and ran it interactively using ./run.cmd from a pwsh prompt in my system. All jobs containing a powershell based task fail with obscure error messages:

See: https://jessehouwing.net/vsbuild-task-fails-on-self-hosted-azure-pipelines-agent/

Turns out this is caused by launching the agent from a powershell core prompt. Stopping the agent and starting it from PowerShell 5.1 or from a Windows Shell solves the issue. Would be nice if the agent detected this and would fail to start with a proper error message.

Versions

Azure DevOps Service Windows 11 version 22H2 (0S Build 22621.2283) Azure Pipelines Agent 3.225.0 VSBuild task: 1.214.0

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

  • [X] 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 11 version 22H2 (0S Build 22621.2283)

Version controll system

Git

Relevant log output

2023-09-18T13:24:55.1897667Z ##[section]Starting: VSBuild
2023-09-18T13:24:55.2042232Z ==============================================================================
2023-09-18T13:24:55.2042611Z Task         : Visual Studio build
2023-09-18T13:24:55.2042705Z Description  : Build with MSBuild and set the Visual Studio version property
2023-09-18T13:24:55.2042827Z Version      : 1.214.0
2023-09-18T13:24:55.2042907Z Author       : Microsoft Corporation
2023-09-18T13:24:55.2042985Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/visual-studio-build
2023-09-18T13:24:55.2043127Z ==============================================================================
2023-09-18T13:24:56.8956825Z ##[error]The following error occurred while loading the extended type data file: Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member AuditToString is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member AccessToString is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Sddl is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Access is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Group is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Owner is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Path is already present.

2023-09-18T13:24:57.0291684Z ##[error]The 'ConvertTo-SecureString' command was found in the module 'Microsoft.PowerShell.Security', but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Security'.
2023-09-18T13:24:57.0552980Z ##[section]Finishing: VSBuild
Enter fullscreen mode Exit fullscreen mode

Workaround:

Set the agent knob AZP_AGENT_CLEANUP_PSMODULES_IN_POWERSHELL on the agent prior to launching the agent:

$env:AZP_AGENT_CLEANUP_PSMODULES_IN_POWERSHELL="true"
.\run.cmd
Enter fullscreen mode Exit fullscreen mode

You can also add this as a variable to your pipeline.

Top comments (0)