måndag 19 mars 2012

Index and length must refer to a location within the string. Parameter name: length

The below error was caused by that Language in the web browser was set to Hungarian (hu-HU).
This problem was resolved by hardcode the culture setting on the MaskedEditExtender object.
In this case it was set to Swedish (SV-SE)

<cc1:MaskedEditExtender ID="maskeditTime" runat="server" TargetControlID="TextBoxTime" MaskType="Time" Mask="99:99" ClearMaskOnLostFocus="false" CultureName="sv-SE"/>

The error print:

Index and length must refer to a location within the string.
Parameter name: length
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.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length
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:

[ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length]
   System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +7495179
   System.String.Substring(Int32 startIndex, Int32 length) +11
   AjaxControlToolkit.MaskedEditExtender.OnLoad(EventArgs e) +785
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3625; ASP.NET Version:2.0.50727.3634