Server Error in '/' Application.

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:


Line 119:      
Line 120:        Do While offset < sb.Length
Line 121:            Dim pos As Integer = sb.ToString(offset - 5, 10).IndexOf("=0D=0A")
Line 122:            If pos = -1 Then
Line 123:                sb.Insert(offset - 5 + pos, "=" & vbCrLf)

Source File: D:\HostingSpaces\hevftzhh\viqtoria.se\wwwroot\Events\Download.ashx    Line: 121

Stack Trace:


[ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length]
   System.Text.StringBuilder.ToString(Int32 startIndex, Int32 length) +13117544
   DownloadEvent.EncodeProperty(String key, String value) in D:\HostingSpaces\hevftzhh\viqtoria.se\wwwroot\Events\Download.ashx:121
   DownloadEvent.writeCalEntry(Int32 EventID, TextWriter output, String url) in D:\HostingSpaces\hevftzhh\viqtoria.se\wwwroot\Events\Download.ashx:96
   DownloadEvent.ProcessRequest(HttpContext context) in D:\HostingSpaces\hevftzhh\viqtoria.se\wwwroot\Events\Download.ashx:27
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +195
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +73


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