Forums / Bugs & Issues / Index was outside the bounds of the array.

Index was outside the bounds of the array.

3 posts, 1 answered
  1. Ted Carter
    Ted Carter avatar
    2 posts
    10 Mar 2020
    25 Aug 2021
    Link to this post
    Using TPC with Dynamics and SiteFinity.  This week without any apparent changes on our end, all of our SiteFinity pages containing a Grid or Form that connects to Dynamics via TPC are showing the following error:

    Server Error in '/' Application.

    Index was outside the bounds of the array.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    Stack Trace:

    [IndexOutOfRangeException: Index was outside the bounds of the array.] System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +5605668 pavliks.PortalConnector.Mvc.PortalLicensingPageRouteHandler.ValidateTpcLicensing(HttpContextBase httpContext, HttpValidationStatus& status) +2264 pavliks.PortalConnector.Mvc.PortalLicensingPageRouteHandler.BuildHttpHandler(RequestContext requestContext) +123 System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +219 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +223 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +220 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +94

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4330.0

    Any suggestions for how to resolve this?  
  2. Vladyslav Makar
    Vladyslav Makar avatar
    20 posts
    16 Dec 2020
    10 Sep 2021 in reply to Ted Carter
    Link to this post
    Greetings Ted,

    Thanks for reaching us at The Portal Connector Forum!

    Would you be able to check if the TPC License is matching the Sitefinity version, please?

    Otherwise, for a specific situation like this - I would recommend reaching us at, where a Case could be created and you would be able to get 1-on-1 assistance from a developer.

    Best regards,

  3. rwanda mc
    rwanda mc avatar
    1 posts
    12 Jan 2022
    11 Jan 2022
    Link to this post
    This exception means that you're trying to access a collection item by index, using an invalid index. An index is invalid when it's lower than the collection's lower bound or greater than or equal to the number of elements it contains. Indexing an empty list will always throw an exception. Use a method like Add to append the item to the end of the list, or Insert to place the item in the middle of the list somewhere, etc. You cannot index into a c# list if that offset doesn't exist.  IndexOutOfRangeException exception is thrown as a result of developer error. Instead of handling the exception, you should diagnose the cause of the error and correct your code. 

    Handling the Exception:

    Use for-each loop: This automatically handles indices while accessing the elements of an array.

    Use Try-Catch: Consider enclosing your code inside a try-catch statement and manipulate the exception accordingly. As mentioned, C# won’t let you access an invalid index and will definitely throw an IndexOutOfRangeException. However, we should be careful inside the block of the catch statement, because if we don’t handle the exception appropriately, we may conceal it and thus, create a bug in your application.
3 posts, 1 answered