SonarAnalyzer throwing ArgumentOutOfRangeException on Azure DevOps

  • ALM used - Azure DevOps
  • CI system used - Azure DevOps
  • Scanner used - SonarQube Cloud 3.3.0 / SonarCloudPrepare@3 / DotNetCoreCLI@2
  • Language - C#
  • Error observed - SonarAnalyzer is throwing ArgumentOutOfRange exceptions when analyzing an otherwise harmless-looking C# file.
  • Steps to reproduce
    • Run the SonarCloudPrepare@3 task in Azure DevOps
    • Use DotNetCoreCLI@2 command: 'build' to build a .NET 8 WPF C# project containing only ResourceColors.cs (below)
  • Potential workaround: delete line 70 FlagBlueBrush of ResourceColors.cs
    OR delete line 11 ExcludeFromCodeCoverage attribute
    OR delete line 38 PeacockBlueDark1
    OR delete line 86 DarkSkyBlueLightHoverBrush
    OR delete line 90 IceHoverBrush
    OR add a new SolidColorBrush after line 102
    OR delete the blank lines within the Color and SolidColorBrush code sections, and realign the equal signs within each section
    OR delete all end-of-line comments
    OR change all integer literals to hex notation (e.g. 0xe2)

The workarounds make me suspect this is a bug in SonarAnalyzer.

Errors (also shown in Build log farther below)

  • CSC : warning AD0001: Analyzer ‘SonarAnalyzer.CSharp.Rules.CopyPasteTokenAnalyzer’ threw an exception of type ‘System.ArgumentOutOfRangeException’ with message ‘Specified argument was out of the range of valid values. (Parameter ‘position’)’.
  • CSC : warning AD0001: Analyzer ‘SonarAnalyzer.CSharp.Rules.MetricsAnalyzer’ threw an exception of type ‘System.ArgumentOutOfRangeException’ with message ‘Specified argument was out of the range of valid values. (Parameter ‘position’)’.

Build log

2025-05-27T15:12:34.1645643Z ##[section]Starting: Build
2025-05-27T15:12:34.1656611Z ==============================================================================
2025-05-27T15:12:34.1656924Z Task         : .NET Core
2025-05-27T15:12:34.1656986Z Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
2025-05-27T15:12:34.1657128Z Version      : 2.256.3
2025-05-27T15:12:34.1657188Z Author       : Microsoft Corporation
2025-05-27T15:12:34.1657271Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2025-05-27T15:12:34.1657369Z ==============================================================================
2025-05-27T15:12:34.7536704Z [command]C:\Windows\system32\chcp.com 65001
2025-05-27T15:12:34.7681262Z Active code page: 65001
2025-05-27T15:12:34.7800150Z Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
2025-05-27T15:12:34.8471663Z [command]"C:\Program Files\dotnet\dotnet.exe" build D:\a\1\s\cube-recorder2.sln "-dl:CentralLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.256.3\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"*ForwardingLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.256.3\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"" --configuration Release /p:TreatWarningsAsErrors=true /p:SourceRevisionId=sandbox/test-sonar-warning|b29c62fd1|build-time_2025-05-27T15:12:33.9341847+00:00_ /p:Verbosity=detailed
2025-05-27T15:12:35.9915035Z   Determining projects to restore...
2025-05-27T15:12:36.5800385Z   Restored D:\a\1\s\WpfUtilities\WpfUtilities.csproj (in 186 ms).
2025-05-27T15:13:10.1747918Z ##[warning]CSC(0,0): Warning AD0001: Analyzer 'SonarAnalyzer.CSharp.Rules.CopyPasteTokenAnalyzer' threw an exception of type 'System.ArgumentOutOfRangeException' with message 'Specified argument was out of the range of valid values. (Parameter 'position')'.
2025-05-27T15:13:10.1760776Z CSC : warning AD0001: Analyzer 'SonarAnalyzer.CSharp.Rules.CopyPasteTokenAnalyzer' threw an exception of type 'System.ArgumentOutOfRangeException' with message 'Specified argument was out of the range of valid values. (Parameter 'position')'. [D:\a\1\s\WpfUtilities\WpfUtilities.csproj]
2025-05-27T15:13:10.1764350Z ##[warning]CSC(0,0): Warning AD0001: Analyzer 'SonarAnalyzer.CSharp.Rules.MetricsAnalyzer' threw an exception of type 'System.ArgumentOutOfRangeException' with message 'Specified argument was out of the range of valid values. (Parameter 'position')'.
2025-05-27T15:13:10.1766059Z CSC : warning AD0001: Analyzer 'SonarAnalyzer.CSharp.Rules.MetricsAnalyzer' threw an exception of type 'System.ArgumentOutOfRangeException' with message 'Specified argument was out of the range of valid values. (Parameter 'position')'. [D:\a\1\s\WpfUtilities\WpfUtilities.csproj]
2025-05-27T15:13:10.2019257Z   WpfUtilities -> D:\a\1\s\WpfUtilities\bin\Release\net8.0-windows\win-x64\WpfUtilities.dll
2025-05-27T15:13:10.2359337Z   Sonar: (WpfUtilities.csproj) Project processed successfully
2025-05-27T15:13:10.2425200Z 
2025-05-27T15:13:10.2435281Z Build succeeded.
2025-05-27T15:13:10.2436680Z 
2025-05-27T15:13:10.2462540Z CSC : warning AD0001: Analyzer 'SonarAnalyzer.CSharp.Rules.CopyPasteTokenAnalyzer' threw an exception of type 'System.ArgumentOutOfRangeException' with message 'Specified argument was out of the range of valid values. (Parameter 'position')'. [D:\a\1\s\WpfUtilities\WpfUtilities.csproj]
2025-05-27T15:13:10.2463916Z CSC : warning AD0001: Analyzer 'SonarAnalyzer.CSharp.Rules.MetricsAnalyzer' threw an exception of type 'System.ArgumentOutOfRangeException' with message 'Specified argument was out of the range of valid values. (Parameter 'position')'. [D:\a\1\s\WpfUtilities\WpfUtilities.csproj]
2025-05-27T15:13:10.2464722Z     2 Warning(s)
2025-05-27T15:13:10.2466395Z     0 Error(s)
2025-05-27T15:13:10.2466851Z 
2025-05-27T15:13:10.2467282Z Time Elapsed 00:00:35.01
2025-05-27T15:13:10.2474144Z 
2025-05-27T15:13:10.2475543Z Workload updates are available. Run `dotnet workload list` for more information.
2025-05-27T15:13:10.2585660Z 
2025-05-27T15:13:10.2903400Z Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
2025-05-27T15:13:10.3027886Z ##[section]Finishing: Build

ResourceColors.cs

using System.Diagnostics.CodeAnalysis;
using System.Windows.Media;

namespace CathVision.Cube.Recorder.WpfUtilities
{
    /// <summary>
    ///     When adding new colors use the following URL to get a name:
    ///     https://colors.artyclick.com/color-name-finder/
    ///     Sorted in numerical order
    /// </summary>
    [ExcludeFromCodeCoverage(Justification = "Just a color dictionary")]
    public static class ResourceColors
    {
        public static readonly Color Transparent             = Color.FromArgb(0x00, 0x00, 0x00, 0x00);
        public static readonly Color Black                   = Color.FromRgb(0x00, 0x00, 0x00);        //#000000
        public static readonly Color GreenHaze               = Color.FromRgb(0x00, 0xb6, 0x3c);        //#00b63c (ButterscotchTwo but green)
        public static readonly Color HighContrastGreen       = Color.FromRgb(0x07, 0xe8, 0x03);        //#07E803
        public static readonly Color BattleshipGrey          = Color.FromRgb(0x6e, 0x7f, 0x7c);        //#6e7f7c
        public static readonly Color Silver                  = Color.FromRgb(0xB7, 0xBF, 0xBE);        //#b7bfbe
        public static readonly Color ClockGreyDark           = Color.FromRgb(0xba, 0xba, 0xba);        //#bababa
        public static readonly Color Ice                     = Color.FromRgb(0xea, 0xf0, 0xef);        //#eaf0ef
        public static readonly Color IceHover                = Color.FromRgb(0xCB, 0xDA, 0xD8);        //##CBDAD8
        public static readonly Color IceWith20Transparency   = Color.FromArgb(0xCC, 0xea, 0xf0, 0xef); //#e6eaf0ef
        public static readonly Color RecordRed               = Color.FromRgb(0xff, 0x3c, 0x46);        //#ff3c46
        public static readonly Color HighContrastRed         = Color.FromRgb(0xff, 0x0f, 0x1b);        //#FF0F1B
        public static readonly Color ButterscotchTwo         = Color.FromRgb(0xff, 0xb6, 0x3c);        //#ffb63c
        public static readonly Color White                   = Color.FromRgb(0xff, 0xff, 0xff);        //#ffffff
        public static readonly Color WarningYellow           = Color.FromRgb(0xf3, 0xc8, 0x36);        //#f3c836
        public static readonly Color HighContrastYellow      = Color.FromRgb(0xff, 0xf5, 0x11);        //#FFF511
        public static readonly Color BackgroundGrey          = Color.FromRgb(0x3A, 0x3A, 0x3A);        //#3A3A3A
        public static readonly Color TransparentBlack        = Color.FromArgb(130,  0,    0,    0);
        public static readonly Color SemitransparentCoolGrey = Color.FromArgb(0x93, 0x9f, 0x9d, 128);

        public static readonly Color StopWatchPink   = Color.FromRgb(216, 4,  148); //#80494
        public static readonly Color StopWatchPurple = Color.FromRgb(112, 84, 220); //#7054dc

        public static readonly Color PeacockBlueDark2  = Color.FromRgb(0x00, 0x3E, 0x4F); //#003E4F
        public static readonly Color PeacockBlueDark1  = Color.FromRgb(0x00, 0x53, 0x6A); //#00536A
        public static readonly Color PeacockBlue       = Color.FromRgb(0x00, 0x68, 0x85); //#006885x
        public static readonly Color PeacockBlueLight1 = Color.FromRgb(0x33, 0x7A, 0x94); //#337A94
        public static readonly Color PeacockBlueLight2 = Color.FromRgb(0x66, 0x8D, 0xA3); //#668DA3
        public static readonly Color PeacockBlueLight4 = Color.FromRgb(0xe5, 0xef, 0xf2); //#e5eff2 (90% lighter version of PeacockBlue)

        public static readonly Color FlagBlue = Color.FromRgb(88, 255, 254); //#58FFFE

        public static readonly Color TealBlue      = Color.FromRgb(0x00, 0x95, 0xa6); //#0095a6
        public static readonly Color TealBlueDark1 = Color.FromRgb(0x00, 0x4C, 0x55); //#004C55
        public static readonly Color TealBlueDark2 = Color.FromRgb(0x00, 0x39, 0x40); //#003940

        public static readonly Color TonedBlue             = Color.FromRgb(0x10, 0x64, 0x76); //#106476
        public static readonly Color GreenBlue             = Color.FromRgb(0x00, 0xab, 0xa0); //#00aba0
        public static readonly Color GreenBlueHover        = Color.FromRgb(0x5d, 0xaa, 0x9B); //#5DAA9B
        public static readonly Color CathVisionLogoBlue    = Color.FromRgb(0x09, 0x43, 0x5a); //#09435A
        public static readonly Color ScreenBg              = Color.FromRgb(0x27, 0x27, 0x27); //#272727
        public static readonly Color ScreenBgAccent        = Color.FromRgb(0x67, 0x67, 0x67); //#373737
        public static readonly Color DarkSkyBlueHover      = Color.FromRgb(0x41, 0x8d, 0xc9); //#418dc9
        public static readonly Color DarkSkyBlue           = Color.FromRgb(0x4d, 0xa7, 0xed); //#4da7ed (85% darker version of DarkSkyBlue)
        public static readonly Color CoolGrey              = Color.FromRgb(0x93, 0x9f, 0x9d); //#939f9d
        public static readonly Color DarkSkyBlueLightHover = Color.FromRgb(0xca, 0xe5, 0xfa); //#cae5fa
        public static readonly Color ClockGrey             = Color.FromRgb(0xcf, 0xcf, 0xcf); //#cfcfcf
        public static readonly Color PaleAqua              = Color.FromRgb(0xd2, 0xde, 0xdb); //#d2dedb
        public static readonly Color PaleGrey              = Color.FromRgb(0xf4, 0xf7, 0xf7); //#f4f7f7

        public static readonly Color CarolinaBlue = Color.FromRgb(0x59, 0xa4, 0xda); //#59a4da

        public static readonly SolidColorBrush BlackBrush                 = MakeBrush(Black);
        public static readonly SolidColorBrush PeacockBlueBrush           = MakeBrush(PeacockBlue);
        public static readonly SolidColorBrush PeacockBlueLight2Brush     = MakeBrush(PeacockBlueLight2);
        public static readonly SolidColorBrush PeacockBlueLight4Brush     = MakeBrush(PeacockBlueLight4);
        public static readonly SolidColorBrush FlagBlueBrush              = MakeBrush(FlagBlue);
        public static readonly SolidColorBrush TealBlueBrush              = MakeBrush(TealBlue);
        public static readonly SolidColorBrush TonedBlueBrush             = MakeBrush(TonedBlue);
        public static readonly SolidColorBrush GreenBlueBrush             = MakeBrush(GreenBlue);
        public static readonly SolidColorBrush GreenBlueHoverBrush        = MakeBrush(GreenBlueHover);
        public static readonly SolidColorBrush GreenHazeBrush             = MakeBrush(GreenHaze);
        public static readonly SolidColorBrush HighContrastGreenBrush     = MakeBrush(HighContrastGreen);
        public static readonly SolidColorBrush CathVisionLogoBlueBrush    = MakeBrush(CathVisionLogoBlue);
        public static readonly SolidColorBrush ScreenBgBrush              = MakeBrush(ScreenBg);
        public static readonly SolidColorBrush ScreenBgAccentBrush        = MakeBrush(ScreenBgAccent);
        public static readonly SolidColorBrush DarkSkyBlueHoverBrush      = MakeBrush(DarkSkyBlueHover);
        public static readonly SolidColorBrush DarkSkyBlueBrush           = MakeBrush(DarkSkyBlue);
        public static readonly SolidColorBrush BattleshipGreyBrush        = MakeBrush(BattleshipGrey);
        public static readonly SolidColorBrush CoolGreyBrush              = MakeBrush(CoolGrey);
        public static readonly SolidColorBrush SilverBrush                = MakeBrush(Silver);
        public static readonly SolidColorBrush ClockGreyDarkBrush         = MakeBrush(ClockGreyDark);
        public static readonly SolidColorBrush DarkSkyBlueLightHoverBrush = MakeBrush(DarkSkyBlueLightHover);
        public static readonly SolidColorBrush ClockGreyBrush             = MakeBrush(ClockGrey);
        public static readonly SolidColorBrush PaleAquaBrush              = MakeBrush(PaleAqua);
        public static readonly SolidColorBrush IceBrush                   = MakeBrush(Ice);
        public static readonly SolidColorBrush IceHoverBrush              = MakeBrush(IceHover);
        public static readonly SolidColorBrush PaleGreyBrush              = MakeBrush(PaleGrey);
        public static readonly SolidColorBrush RecordRedBrush             = MakeBrush(RecordRed);
        public static readonly SolidColorBrush HighContrastRedBrush       = MakeBrush(HighContrastRed);
        public static readonly SolidColorBrush ButterscotchTwoBrush       = MakeBrush(ButterscotchTwo);
        public static readonly SolidColorBrush WhiteBrush                 = MakeBrush(White);
        public static readonly SolidColorBrush WarningYellowBrush         = MakeBrush(WarningYellow);
        public static readonly SolidColorBrush HighContrastYellowBrush    = MakeBrush(HighContrastYellow);
        public static readonly SolidColorBrush BackgroundGreyBrush        = MakeBrush(BackgroundGrey);
        public static readonly SolidColorBrush TransparentBrush           = MakeBrush(Transparent);

        public static readonly SolidColorBrush StopWatchPinkBrush   = MakeBrush(StopWatchPink);
        public static readonly SolidColorBrush StopWatchPurpleBrush = MakeBrush(StopWatchPurple);

        /// <summary>
        ///     Returns either white or black depending on (background) color given.
        /// </summary>
        /// <param name="backgroundColor">The background color.</param>
        /// <returns>Black or white.</returns>
        public static Color GetForegroundColor(Color backgroundColor) => ShouldBeBlack(backgroundColor) ? Black : White;

        /// <summary>
        ///     Returns either white or black depending on (background) color given.
        /// </summary>
        /// <param name="backgroundBrush">The background color.</param>
        /// <returns>Black or white.</returns>
        public static SolidColorBrush GetForegroundColor(SolidColorBrush backgroundBrush) => ShouldBeBlack(backgroundBrush.Color) ? BlackBrush : WhiteBrush;

        private static bool ShouldBeBlack(Color backgroundColor) => CalculateBrightness(backgroundColor) > 127;

        /// <summary>
        ///     https://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
        /// </summary>
        private static int CalculateBrightness(Color backgroundColor) =>
            (int)Math.Sqrt(
                backgroundColor.R * backgroundColor.R * .241 +
                backgroundColor.G * backgroundColor.G * .691 +
                backgroundColor.B * backgroundColor.B * .068);

        private static SolidColorBrush MakeBrush(Color color)
        {
            SolidColorBrush brush = new(color);
            brush.Freeze();
            return brush;
        }
    }
}
1 Like

Hello @joel-cathvision

I tested the provided code snippet in different scenarios including a SonarCloud scan as described by you. I used the windows-latest image and the DotNetCoreCLI@2 task and <TargetFramework>net8.0-windows</TargetFramework> in the csproj.

I wasn’t able to reproduce the AD0001 warnings in ResourceColors.cs

Can you post a bit more details about the .Net SDK installed and used on your build machine.

Can you also add #error version somewhere in your code and run the pipeline with this snippet in it. It should result in compiler error CS8304 Compiler version: '4.13.0-3.25167.3 (73eff2b5)'. Language version: 12.0. or similar and shows the version of Roslyn (C# compiler) used.

Hi @Martin_Strecker

Thanks for your reply!

I’m sorry to hear you cannot reproduce.

sonar-out-of-range.zip (23.7 KB)
Here’s a zip of a minimal reproducing solution, including the DevOps yaml.
It reproduces the error, except that I’ve redacted our information from Sonar step parameters in RL-build-analyze-publish-steps.yml, e.g. organization: 'redact-organization'.

We build with the windows-2022 image (should be same as windows-latest), which originally failed using 9.0.203 SDK. I re-ran the failing build now, and windows-2022 now uses 9.0.330 SDK. The full output of dotnet info from today’s build is shown in the Stage info log below.

I added #error version as you requested:
CS8304: Compiler version: '4.14.0-3.25218.8 (d7bde97e)'. Language version: latest (13.0).

I’ve also included the Initialize job part of the build log below.

Build log “Stage info”

2025-06-08T11:01:27.8901164Z ##[section]Starting: Display: Stage Info
2025-06-08T11:01:27.8911347Z ==============================================================================
2025-06-08T11:01:27.8911540Z Task         : PowerShell
2025-06-08T11:01:27.8911625Z Description  : Run a PowerShell script on Linux, macOS, or Windows
2025-06-08T11:01:27.8911776Z Version      : 2.247.1
2025-06-08T11:01:27.8911858Z Author       : Microsoft Corporation
2025-06-08T11:01:27.8911956Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2025-06-08T11:01:27.8912124Z ==============================================================================
2025-06-08T11:01:29.5858486Z Generating script.
2025-06-08T11:01:29.6506820Z ========================== Starting Command Output ===========================
2025-06-08T11:01:29.7788624Z ##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\ebd72790-861f-4600-9096-105828fc0b99.ps1'"
2025-06-08T11:01:30.1659331Z 
2025-06-08T11:01:30.1662290Z ===========
2025-06-08T11:01:30.1664839Z dotnet info
2025-06-08T11:01:30.1667310Z ===========
2025-06-08T11:01:36.4701800Z .NET SDK:
2025-06-08T11:01:36.4702436Z  Version:           9.0.300
2025-06-08T11:01:36.4702707Z  Commit:            15606fe0a8
2025-06-08T11:01:39.0289394Z  Workload version:  9.0.300-manifests.69179adf
2025-06-08T11:01:39.5208950Z  MSBuild version:   17.14.5+edd3bbf37
2025-06-08T11:01:39.5209492Z 
2025-06-08T11:01:39.5209808Z Runtime Environment:
2025-06-08T11:01:39.5227832Z  OS Name:     Windows
2025-06-08T11:01:39.5228363Z  OS Version:  10.0.20348
2025-06-08T11:01:39.5252708Z  OS Platform: Windows
2025-06-08T11:01:39.5844327Z  RID:         win-x64
2025-06-08T11:01:39.5845086Z  Base Path:   C:\Program Files\dotnet\sdk\9.0.300\
2025-06-08T11:01:39.5845287Z 
2025-06-08T11:01:39.5845545Z .NET workloads installed:
2025-06-08T11:01:40.4691567Z There are no installed workloads to display.
2025-06-08T11:01:40.4694850Z Configured to use loose manifests when installing new manifests.
2025-06-08T11:01:41.4641745Z 
2025-06-08T11:01:41.4643720Z Host:
2025-06-08T11:01:41.4644168Z   Version:      9.0.5
2025-06-08T11:01:41.4644546Z   Architecture: x64
2025-06-08T11:01:41.4644916Z   Commit:       e36e4d1a8f
2025-06-08T11:01:41.4645161Z 
2025-06-08T11:01:41.4651706Z .NET SDKs installed:
2025-06-08T11:01:41.4652559Z   6.0.136 [C:\Program Files\dotnet\sdk]
2025-06-08T11:01:41.4652792Z   6.0.203 [C:\Program Files\dotnet\sdk]
2025-06-08T11:01:41.4653085Z   6.0.321 [C:\Program Files\dotnet\sdk]
2025-06-08T11:01:41.4653308Z   6.0.428 [C:\Program Files\dotnet\sdk]
2025-06-08T11:01:41.4653530Z   8.0.116 [C:\Program Files\dotnet\sdk]
2025-06-08T11:01:41.4653760Z   8.0.206 [C:\Program Files\dotnet\sdk]
2025-06-08T11:01:41.4653982Z   8.0.313 [C:\Program Files\dotnet\sdk]
2025-06-08T11:01:41.4654203Z   8.0.410 [C:\Program Files\dotnet\sdk]
2025-06-08T11:01:41.4654430Z   9.0.106 [C:\Program Files\dotnet\sdk]
2025-06-08T11:01:41.4654667Z   9.0.200 [C:\Program Files\dotnet\sdk]
2025-06-08T11:01:41.4654887Z   9.0.204 [C:\Program Files\dotnet\sdk]
2025-06-08T11:01:41.4655107Z   9.0.300 [C:\Program Files\dotnet\sdk]
2025-06-08T11:01:41.4655214Z 
2025-06-08T11:01:41.4655397Z .NET runtimes installed:
2025-06-08T11:01:41.4655667Z   Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
2025-06-08T11:01:41.4655991Z   Microsoft.AspNetCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
2025-06-08T11:01:41.4656362Z   Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
2025-06-08T11:01:41.4656690Z   Microsoft.AspNetCore.App 6.0.38 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
2025-06-08T11:01:41.4657018Z   Microsoft.AspNetCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
2025-06-08T11:01:41.4657337Z   Microsoft.AspNetCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
2025-06-08T11:01:41.4659471Z   Microsoft.AspNetCore.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
2025-06-08T11:01:41.4659793Z   Microsoft.AspNetCore.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
2025-06-08T11:01:41.4660131Z   Microsoft.AspNetCore.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
2025-06-08T11:01:41.4660451Z   Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2025-06-08T11:01:41.4660787Z   Microsoft.NETCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2025-06-08T11:01:41.4661109Z   Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2025-06-08T11:01:41.4661419Z   Microsoft.NETCore.App 6.0.38 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2025-06-08T11:01:41.4661731Z   Microsoft.NETCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2025-06-08T11:01:41.4662037Z   Microsoft.NETCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2025-06-08T11:01:41.4662360Z   Microsoft.NETCore.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2025-06-08T11:01:41.4662666Z   Microsoft.NETCore.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2025-06-08T11:01:41.4662969Z   Microsoft.NETCore.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2025-06-08T11:01:41.4663289Z   Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
2025-06-08T11:01:41.4663765Z   Microsoft.WindowsDesktop.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
2025-06-08T11:01:41.4664104Z   Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
2025-06-08T11:01:41.4664437Z   Microsoft.WindowsDesktop.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
2025-06-08T11:01:41.4664781Z   Microsoft.WindowsDesktop.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
2025-06-08T11:01:41.4665129Z   Microsoft.WindowsDesktop.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
2025-06-08T11:01:41.4665475Z   Microsoft.WindowsDesktop.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
2025-06-08T11:01:41.4665813Z   Microsoft.WindowsDesktop.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
2025-06-08T11:01:41.4665959Z 
2025-06-08T11:01:41.4666143Z Other architectures found:
2025-06-08T11:01:41.4666364Z   x86   [C:\Program Files (x86)\dotnet]
2025-06-08T11:01:41.4666635Z     registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
2025-06-08T11:01:41.4666780Z 
2025-06-08T11:01:41.4666971Z Environment variables:
2025-06-08T11:01:41.4667166Z   Not set
2025-06-08T11:01:41.4667238Z 
2025-06-08T11:01:41.4667417Z global.json file:
2025-06-08T11:01:41.4667607Z   Not found
2025-06-08T11:01:41.4667683Z 
2025-06-08T11:01:41.4667856Z Learn more:
2025-06-08T11:01:41.4668047Z   https://aka.ms/dotnet/info
2025-06-08T11:01:41.4668161Z 
2025-06-08T11:01:41.4670304Z Download .NET:
2025-06-08T11:01:41.4670766Z   https://aka.ms/dotnet/download
2025-06-08T11:01:41.4898295Z 
2025-06-08T11:01:41.6325302Z ##[section]Finishing: Display: Stage Info

Build log “Initialize job”

2025-06-08T10:59:49.6276050Z ##[section]Starting: Initialize job
2025-06-08T10:59:49.6279793Z Agent name: 'Hosted Agent'
2025-06-08T10:59:49.6280358Z Agent machine name: 'fv-az899-384'
2025-06-08T10:59:49.6280633Z Current agent version: '4.255.0'
2025-06-08T10:59:49.6314585Z ##[group]Operating System
2025-06-08T10:59:49.6315029Z Microsoft Windows Server 2022
2025-06-08T10:59:49.6315270Z 10.0.20348
2025-06-08T10:59:49.6315467Z Datacenter
2025-06-08T10:59:49.6315687Z ##[endgroup]
2025-06-08T10:59:49.6315915Z ##[group]Runner Image
2025-06-08T10:59:49.6316140Z Image: windows-2022
2025-06-08T10:59:49.6316380Z Version: 20250602.1.0
2025-06-08T10:59:49.6316729Z Included Software: https://github.com/actions/runner-images/blob/win22/20250602.1/images/windows/Windows2022-Readme.md
2025-06-08T10:59:49.6317165Z Image Release: https://github.com/actions/runner-images/releases/tag/win22%2F20250602.1
2025-06-08T10:59:49.6317439Z ##[endgroup]
2025-06-08T10:59:49.6318328Z ##[group]Runner Image Provisioner
2025-06-08T10:59:49.6318580Z 2.0.437.1
2025-06-08T10:59:49.6318833Z ##[endgroup]
2025-06-08T10:59:49.6322940Z Current image version: '20250602.1.0'
2025-06-08T10:59:49.7695902Z Agent running as: 'VssAdministrator'
2025-06-08T10:59:49.7740933Z Prepare build directory.
2025-06-08T10:59:49.8012350Z Set build variables.
2025-06-08T10:59:49.8033796Z Download all required tasks.
2025-06-08T10:59:49.8127422Z Downloading task: PowerShell (2.247.1)
2025-06-08T10:59:50.5814224Z Downloading task: DotNetCoreCLI (2.256.3)
2025-06-08T10:59:52.1868282Z Downloading task: SonarCloudPrepare (3.3.0)
2025-06-08T10:59:52.5538140Z Downloading task: SonarCloudAnalyze (3.3.0)
2025-06-08T10:59:53.0073113Z Downloading task: SonarCloudPublish (3.3.0)
2025-06-08T10:59:53.0546520Z Downloading task: sonarcloud-buildbreaker (2.1.3)
2025-06-08T10:59:53.5518001Z Checking job knob settings.
2025-06-08T10:59:53.5521889Z    Knob: DockerActionRetries = true Source: $(VSTSAGENT_DOCKER_ACTION_RETRIES) 
2025-06-08T10:59:53.5522288Z    Knob: AgentToolsDirectory = C:\hostedtoolcache\windows Source: ${AGENT_TOOLSDIRECTORY} 
2025-06-08T10:59:53.5523469Z    Knob: UseGitLongPaths = true Source: $(USE_GIT_LONG_PATHS) 
2025-06-08T10:59:53.5524163Z    Knob: AgentPerflog = c:\vsts\perflog Source: ${VSTS_AGENT_PERFLOG} 
2025-06-08T10:59:53.5525200Z    Knob: EnableIssueSourceValidation = true Source: $(ENABLE_ISSUE_SOURCE_VALIDATION) 
2025-06-08T10:59:53.5525826Z    Knob: AgentEnablePipelineArtifactLargeChunkSize = true Source: $(AGENT_ENABLE_PIPELINEARTIFACT_LARGE_CHUNK_SIZE) 
2025-06-08T10:59:53.5527603Z    Knob: ContinueAfterCancelProcessTreeKillAttempt = true Source: $(VSTSAGENT_CONTINUE_AFTER_CANCEL_PROCESSTREEKILL_ATTEMPT) 
2025-06-08T10:59:53.5528192Z    Knob: ProcessHandlerSecureArguments = false Source: $(AZP_75787_ENABLE_NEW_LOGIC) 
2025-06-08T10:59:53.5528619Z    Knob: ProcessHandlerSecureArguments = false Source: $(AZP_75787_ENABLE_NEW_LOGIC_LOG) 
2025-06-08T10:59:53.5529072Z    Knob: ProcessHandlerTelemetry = true Source: $(AZP_75787_ENABLE_COLLECT) 
2025-06-08T10:59:53.5529517Z    Knob: UseNewNodeHandlerTelemetry = True Source: $(DistributedTask.Agent.USENEWNODEHANDLERTELEMETRY) 
2025-06-08T10:59:53.5529929Z    Knob: ProcessHandlerEnableNewLogic = true Source: $(AZP_75787_ENABLE_NEW_PH_LOGIC) 
2025-06-08T10:59:53.5530531Z    Knob: EnableResourceMonitorDebugOutput = true Source: $(AZP_ENABLE_RESOURCE_MONITOR_DEBUG_OUTPUT) 
2025-06-08T10:59:53.5530978Z    Knob: EnableResourceUtilizationWarnings = true Source: $(AZP_ENABLE_RESOURCE_UTILIZATION_WARNINGS) 
2025-06-08T10:59:53.5531571Z    Knob: IgnoreVSTSTaskLib = true Source: $(AZP_AGENT_IGNORE_VSTSTASKLIB) 
2025-06-08T10:59:53.5531930Z    Knob: FailJobWhenAgentDies = true Source: $(FAIL_JOB_WHEN_AGENT_DIES) 
2025-06-08T10:59:53.5532420Z    Knob: CheckForTaskDeprecation = true Source: $(AZP_AGENT_CHECK_FOR_TASK_DEPRECATION) 
2025-06-08T10:59:53.5532986Z    Knob: CheckIfTaskNodeRunnerIsDeprecated246 = False Source: $(DistributedTask.Agent.CheckIfTaskNodeRunnerIsDeprecated246) 
2025-06-08T10:59:53.5535811Z    Knob: UseNode20ToStartContainer = True Source: $(DistributedTask.Agent.UseNode20ToStartContainer) 
2025-06-08T10:59:53.5537251Z    Knob: LogTaskNameInUserAgent = true Source: $(AZP_AGENT_LOG_TASKNAME_IN_USERAGENT) 
2025-06-08T10:59:53.5537669Z    Knob: UseFetchFilterInCheckoutTask = true Source: $(AGENT_USE_FETCH_FILTER_IN_CHECKOUT_TASK) 
2025-06-08T10:59:53.5538155Z    Knob: Rosetta2Warning = true Source: $(ROSETTA2_WARNING) 
2025-06-08T10:59:53.5539056Z    Knob: AddForceCredentialsToGitCheckout = True Source: $(DistributedTask.Agent.AddForceCredentialsToGitCheckout) 
2025-06-08T10:59:53.5539726Z    Knob: UseSparseCheckoutInCheckoutTask = true Source: $(AGENT_USE_SPARSE_CHECKOUT_IN_CHECKOUT_TASK) 
2025-06-08T10:59:53.5540027Z Finished checking job knob settings.
2025-06-08T10:59:53.5967905Z Start tracking orphan processes.
2025-06-08T10:59:53.6013299Z ##[section]Finishing: Initialize job

Hello @joel-cathvision

Thank you for providing all the details from your pipeline. I tried to reproduce the error with our test pipeline here:
https://github.com/SonarSource/sonar-scanner-azdo-test/pull/20

As you can see, the build was successful and I can not reproduce the error. I included all the major parts of your pipeline and copied the ResourceColors.cs from your zip file. The only major change was adding the GenerateDocumentationFile msbuild property.

I’m running out of ideas here. Can you please have a look at the re-producer
https://github.com/SonarSource/sonar-scanner-azdo-test/pull/20
and check if I missed something important?

Sorry for the late reply but I was on vacation the last two weeks.

Best Martin

Hi @Martin_Strecker

Can you put the exact binary version of ResourceColors.cs that I uploaded in sonar-out-of-range.zip into your re-producer on GitHub?

The exceptions disappear from our build when I use the version of ResourceColors.cs from your re-producer. You have changed the C# code, discarding the vertical alignment by removing spaces before the equals signs, compared to the version of ResourceColors.cs that I uploaded in sonar-out-of-range.zip.

The ResourceColors.cs in the zip file still reproduces the error in our build.

This diff shows the changes you’ve made to the code:

Hi again @Martin_Strecker,

I’ve created Update ResourceColors.cs to exact original version by joel-cathvision · Pull Request #21 · SonarSource/sonar-scanner-azdo-test · GitHub with the version of ResourceColors.cs that reproduces the exceptions.

This is the first time I’ve made a pull request to someone else’s public repo in GitHub, so please let me know if I should make it in a different way.

Hi @joel-cathvision

thank you for providing the update. I integrated the changes in my PR:

Our test pipeline is still green :sad_but_relieved_face:, though.
I also can see the metrics and the duplications reported correctly:


The MetricsAnalyzer and the CopyPasteTokenAnalyzer seen in the AD0001 are responsible for producing these two numbers.

We take AD0001 errors very seriously but I’m running out of ideas here. This is very unfortunate but there is nothing we can do at the moment. If you have any further insights about anything I missed during the investigation, please let me know.

Hi @Martin_Strecker,

When I look on Add repo for community 141909 by martin-strecker-sonarsource · Pull Request #20 · SonarSource/sonar-scanner-azdo-test · GitHub there are now 2 warnings, which weren’t there before.

Can you check if they are the two AD0001 warnings? (I don’t have permissions to view them.)

1 Like

That’s indeed the case:

Thanks a lot for pointing this out!
I will look into this further and let you know about my findings now.

2 Likes

Congratulations @joel-cathvision,

it seems you have found a bug in the C# Parser. I still don’t understand the root cause, but I created a re-producer for the Roslyn team to have a look:

There are more reports like yours already (e.g. this one Constant errors regarding "Diagnostic Analyzer runner" crashing · Issue #78025 · dotnet/roslyn · GitHub) which may or may not be related.

I can only tell, that the position of the last token in your file has a wrong location in the parsed syntax-tree and is out of bounds of the document.

Adding a new-line at the end of the document seems to be the easiest fix to me.

We will not fix the error on our side just now but wait for feedback from the Roslyn team instead. If they can re-produce and fix the issue on their end, this issue should be fixed as well.

Cool. Thanks @Martin_Strecker :slightly_smiling_face: