Share via

System.ArgumentOutOfRangeException while deploying AKS template using demo generator

Anubhav Kumar 0 Reputation points
2025-03-19T08:38:02.9066667+00:00

While updating the lab, we encountered an error during the new demo generator process. The error is as follows: "System.ArgumentOutOfRangeException," and it's shown in the screenshot. Could you please share the resolution for this issue?

Template Name: Azure Kubernetes ServiceWhatsApp Image 2025-03-19 at 13.45.36_200a395b

Demo Generator Process: https://github.com/microsoft/AzDevOpsDemoGenerator/blob/main/docs/RunApplication.md

Thank you!

Azure DevOps
0 comments No comments

1 answer

Sort by: Most helpful
  1. Bodapati Harish 825 Reputation points Microsoft External Staff Moderator
    2025-03-21T06:59:36+00:00

    Hello Anubhav Kumar,

    The issue happens when IndexOf("href='") returns -1, means the pattern isn't found. When we add 6 to -1, it results in an invalid index. Similarly, if there’s no closing single quote ('), IndexOf("'", startIndex) also returns -1, causing an invalid substring operation.

    To resolve this, you can try the following steps:

    • First, check if the input string is null or empty to avoid processing invalid data.
    • Then, verify if "href='" exists in the string before trying to extract the value.
    • Also, ensure that there is a closing single quote (') after the "href='" to avoid another invalid index.

    Here’s a better version of the method that avoids these issues:

    
    public string ExtractHref(string link)
    
    {
    
        if (string.IsNullOrEmpty(link))
    
        {
    
            throw new ArgumentException("Input link cannot be null or empty.");
    
        }
    
        var startIndex = link.IndexOf("href='");
    
        if (startIndex == -1)
    
        {
    
            throw new ArgumentException("The provided link does not contain 'href='.");
    
        }
    
        startIndex += 6; 
    
        var endIndex = link.IndexOf("'", startIndex);
    
        if (endIndex == -1)
    
        {
    
            throw new ArgumentException("The href attribute is not properly closed with a single quote.");
    
        }
    
        return link.Substring(startIndex, endIndex - startIndex);
    
    }
    
    
    • It prevents errors by checking for null or empty strings.
    • It ensures the "href='" pattern exists before proceeding.
    • It verifies that a closing single quote exists before trying to extract the value.

    Hope it helps!


    Please do not forget to click "Accept the answer” and Yes wherever the information provided helps you, this can be beneficial to other community memberUser's image

    If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.