locked
the assembly instruction at KERNELBASE!RaiseException in C:\Windows\System32\KERNELBASE.dll from Microsoft Corporation has caused a CLR Exception on thread 50 RRS feed

  • Question

  • User724253887 posted

    Hi,

    My MVC web app crashes with this error very frequently, please help what do i need to fix this.. as far what i see this exception is internal and being raised from KERNELBASE.dll.. 

    please help.. as this affecting our customers a lot..

    <div>In w3wp.exe.132620.dmp the assembly instruction at KERNELBASE!RaiseException in C:\Windows\System32\KERNELBASE.dll from Microsoft Corporation has caused a CLR Exception on thread 50 with the following error information:</div> <div> </div> <div>    Type:   System.IndexOutOfRangeException </div> <div>    Message:   Index was outside the bounds of the array. </div>

    Below is the full stack from DevDebug dump analysis

    Entry point   clr!Thread::intermediateThreadProc
    Create time   12/22/2018 10:28:03 AM
    Time spent in user mode   0 Days 00:00:00.015
    Time spent in kernel mode   0 Days 00:00:00.531


    This thread is not fully resolved and may or may not be a problem. Further analysis of these threads may be required.

    The thread has evidence of .net exceptions on the stack. Check the Previous .NET Exceptions Report (Exceptions in all .NET Thread Stacks) to view more details of the associated exception

    .NET Call Stack

    [[HelperMethodFrame]]
    Galasys.Web.Controllers.TicketExchangeController+<>c__DisplayClass66.<searchticket>b__48</searchticket>(System.Object)+3da
    mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+285
    mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+9
    mscorlib_ni!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()+6f
    mscorlib_ni!System.Threading.ThreadPoolWorkQueue.Dispatch()+1ea
    [[DebuggerU2MCatchHandlerFrame]]
    [[ContextTransitionFrame]]
    [[DebuggerU2MCatchHandlerFrame]]

    Full Call Stack

    ntdll!NtWaitForMultipleObjects+a
    KERNELBASE!WaitForMultipleObjectsEx+e1
    kernel32!WerpReportFaultInternal+581
    kernel32!WerpReportFault+83
    KERNELBASE!UnhandledExceptionFilter+23f
    w3wp!WpUnhandledExceptionFilter+47
    mscoreei!InternalUnhandledExceptionFilter+30
    KERNELBASE!UnhandledExceptionFilter+1a2
    ntdll!RtlUserThreadStart$filt$0+3e
    ntdll!_C_specific_handler+96
    ntdll!RtlpExecuteHandlerForException+d
    ntdll!RtlDispatchException+197
    ntdll!RtlRaiseException+18d
    KERNELBASE!RaiseException+68
    clr!RaiseTheExceptionInternalOnly+2fe
    clr!UnwindAndContinueRethrowHelperAfterCatch+80
    clr!JIT_RngChkFail+7c
    [[HelperMethodFrame]]
    Galasys.Web.Controllers.TicketExchangeController+<>c__DisplayClass66.<SearchTicket>b__48(System.Object)+3da
    mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+285
    mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+9
    mscorlib_ni!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()+6f
    mscorlib_ni!System.Threading.ThreadPoolWorkQueue.Dispatch()+1ea
    clr!CallDescrWorkerInternal+83
    clr!CallDescrWorkerWithHandler+4a
    clr!MethodDescCallSite::CallTargetWorker+251
    clr!QueueUserWorkItemManagedCallback+2a
    clr!ManagedThreadBase_DispatchInner+2d
    clr!ManagedThreadBase_DispatchMiddle+6c
    clr!ManagedThreadBase_DispatchOuter+75
    [[DebuggerU2MCatchHandlerFrame]]
    clr!ManagedThreadBase_DispatchInCorrectAD+15
    clr!Thread::DoADCallBack+2a1
    [[ContextTransitionFrame]]
    clr!ManagedThreadBase_DispatchInner+69
    clr!ManagedThreadBase_DispatchMiddle+6c
    clr!ManagedThreadBase_DispatchOuter+75
    [[DebuggerU2MCatchHandlerFrame]]
    clr!ManagedThreadBase_FullTransitionWithAD+2f
    clr!ManagedPerAppDomainTPCount::DispatchWorkItem+a2
    clr!ThreadpoolMgr::ExecuteWorkRequest+46
    clr!ThreadpoolMgr::WorkerThreadStart+f4
    clr!Thread::intermediateThreadProc+7d
    kernel32!BaseThreadInitThunk+22

    ntdll!RtlUserThreadStart+34

    Thank you,

    Sandeep

    Monday, December 24, 2018 3:42 AM

Answers

  • User-1492487179 posted

    Hi Sandeep,

    this issue is probably caused by the sentence of availDate2.Add(item5); there are more threads try to write data to this list at the same time which will break the list. so please add a lock to this place to avoid this scenario. 

    for try/catch, why it didn't capture the exception, you can refer https://stackoverflow.com/questions/17573467/exception-handling-in-delegate 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 26, 2018 11:13 AM

All replies

  • User-1492487179 posted

    Hi Sandeep,

    To check further, we need the dump file, please help upload the dump to File Transfer - Case 118122519488215

    thanks

    Tuesday, December 25, 2018 9:16 AM
  • User-474980206 posted

    It looks like your action got an index out of range error. Your code should be checking that indexes are in range.
    Tuesday, December 25, 2018 4:42 PM
  • User724253887 posted

    Hi, i have zipped and uploaded the dump file on the URL.

    Thanks for your reply

    Wednesday, December 26, 2018 2:18 AM
  • User724253887 posted

    Thanks for your reply,

    the whole action method is enclosed inside the try-catch block, so there is no chance of exception inside the method is not handled and eventually lead to IIS crash

    public JsonResult SearchTicket(string searchText)
            {
                var success = true;
                var errorMessage = string.Empty;
                var tickets = new List<TicketExchangeModel>();
                var hasGovernmentId = false;
                object calendarInfo = null;
    
                try
                {
                    _log.Debug(string.Format("[TicketExchange] {0} Debug : A", searchText));
                    var appsetting = EFDbContext.NewContext<List<AppSettings>>((con) =>
                    {
                        return con.AppSettings.AsNoTracking().ToList();
                    });
                    var orderId = searchText;
                    
                    _log.Debug(string.Format("[TicketExchange] {0} Debug : B", searchText));
                    tickets = FilterTickets(orderId, ref hasGovernmentId);
                    if (tickets.Any())
                    {
                        #region if-block
                        
                        #endregion
                        }
                        else
                        {
                            #region else-block
                            
                            #endregion
                        }
                    }
                    else
                    {
                        success = false;
                        errorMessage = Resources.Resources.OrderNotExists;
                    }
                }
                catch (Exception ex)
                {
                    success = false;
                    errorMessage = ex.Message;
                    _log.Error(string.Format("[TicketExchange] {0} Exception: {1}", searchText, ex));
                }
    
                return Json(new { success, TicketInfo = tickets, CalendarInfo = calendarInfo, Errormsg = errorMessage, HasGovernmentId = hasGovernmentId });
            }

      

    Wednesday, December 26, 2018 2:29 AM
  • User-1492487179 posted

    Hi Sandeep,

    this issue is probably caused by the sentence of availDate2.Add(item5); there are more threads try to write data to this list at the same time which will break the list. so please add a lock to this place to avoid this scenario. 

    for try/catch, why it didn't capture the exception, you can refer https://stackoverflow.com/questions/17573467/exception-handling-in-delegate 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 26, 2018 11:13 AM
  • User724253887 posted

    Hi,

    Thanks for response,

    can know where exactly you found this line?

    "availDate2.Add(item5)"

    Wednesday, December 26, 2018 11:29 AM
  • User465171450 posted

    Have you tried commenting out the log possibility in the try catch. It is still possible to throw an uncaught error from the catch. That is the only spot I can see that has indexed positions referenced that could generate this error in an uncaught form.

    Wednesday, December 26, 2018 9:02 PM
  • User724253887 posted

    The log in the catch was recently added after the error started appear..

    by the way  developer and qa environment do not have this issue

    Thursday, December 27, 2018 1:48 AM
  • User-1492487179 posted

    Hi Sandeep,

    you can follow path:Galasys.Web.Controllers.TicketExchangeController.SearchTicket(string) to find "public JsonResult SearchTicket(string searchText)" function, and "availDate2.Add(item5)" exist in the below else section:

    else
     {
                    List<DateTime> availDate2 = new List<DateTime>();
                    List<DateTime> list2 = new List<DateTime>();
                    list2 = (from x in Enumerable.Range(0, num)
                    select DateTime.Today.AddDays((double)x)).ToList();
                    List<string> pluList = (from x in plus
                    select x.PLU).ToList();
                    List<PLUItems> itemsList = this._orderProduct.GetItemsWithAllotment(list2.First(), list2.Last(), Sessions.ParentTradeClientId, pluList);
                    if (itemsList != null && itemsList.Any((PLUItems x) => x.HasBalance))
                    {
                        CountdownEvent countdownEvent2 = new CountdownEvent(num);
                        try
                        {
                            foreach (DateTime item5 in list2)
                            {
                                WaitCallback callBack = delegate
                                {
                                    List<Item> list3 = this._orderProduct.GetItems(item5, tradeClientId, pluList).ToList();
                                    if (pluList.Count == list3.Count)
                                    {
                                        List<PLUItems> list4 = itemsList.Where(delegate(PLUItems x)
                                        {
                                            if (x.HasBalance && (!x.EntitlementDate.HasValue || (x.EntitlementDate.Value == item5 && true)))
                                            {
                                                return pluList.Contains(x.PLU);
                                            }
                                            return false;
                                        }).ToList();
                                        if (list4 != null && list4.Count >= pluList.Count)
                                        {
                                            int num2 = 0;
                                            foreach (var item6 in plus)
                                            {
                                                List<Item> source2 = list3;
                                                Func<Item, bool> predicate = (Item x) => x.PLU == item6.PLU;
                                                Item item = source2.Where(predicate).FirstOrDefault();
                                                if (item != null)
                                                {
                                                    if (item.Price != item6.Price)
                                                    {
                                                        break;
                                                    }
                                                    num2++;
                                                }
                                            }
                                            if (pluList.Count() == num2)
                                            {
                                                availDate2.Add(item5);
                                            }
     }
                                    }
                                    countdownEvent2.Signal();
                                };
                                ThreadPool.QueueUserWorkItem(callBack);
                            }
                            countdownEvent2.Wait();
                        }
                        finally
                        {
                            if (countdownEvent2 != null)
                            {
                                ((IDisposable)countdownEvent2).Dispose();
                            }
                        }
                    }

    Wednesday, January 2, 2019 2:10 AM
  • User724253887 posted
    Thank for reply,

    I mean how you are able to extract the full method definition, i haven’t posted my SearchTicket method definition in my previous posts

    What tool have you used to do that.. can i know? Just curious

    Thanks
    Wednesday, January 2, 2019 3:11 AM
  • User-1492487179 posted

    Hi Sandeep,

    we get the method details from the dump you provided last time, we can get the assembly from the dump and then decompile the assembly.

    thanks

    Thursday, January 3, 2019 2:30 AM
  • User724253887 posted
    Hi,

    Sorry to ask , may i know how you have extracted assembly from dump?

    I have tried debugging the dump using visual studuo but couldn’t successfully.

    Thanks
    Thursday, January 3, 2019 4:43 AM
  • User-1492487179 posted

    Hi,

    that's fine, we use windbg tool to analyze the dump and use the command "!mex.writemodule " to get the assembly.

    thanks

    Friday, January 4, 2019 3:13 AM
  • User724253887 posted

    Thnks for the info,

    anyways i have modified my code to lock the multi threaded resource, need to wait for next deployment only then can know if the fix really worked or not.. 

    Friday, January 4, 2019 6:17 AM
  • User-1492487179 posted

    Hi Sandeep,

    hope everything is good.

    has this issue been resolved? 

    thanks,

    Tuesday, January 15, 2019 11:14 AM
  • User724253887 posted

    Hi,

    we are yet to move the changes to prod, can only know if the fix worked once it is up in prod.. will update here

    Thanks

    Thursday, January 17, 2019 4:13 AM
  • User724253887 posted

    Hi,

    we have recently moved changes to prod and the fix worked..

    Thanks a lot man

    Friday, January 25, 2019 3:13 PM