Skip to content

'The type initializer for 'HandyControl.Controls.Window' threw an exception.' #442

Open

Description

@DineshSolanki

The exception occurs at Messagebox.Show/Ask/Error etc calls.
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

To Reproduce
Steps to reproduce the behavior:
This happens randomly and I couldn't find the exact way to reproduce.

Environment (please complete the following information):

  • .net: [.net core 3.1
  • IDE [e.g. vs2019]
  • Version [2.5.3.2]
Stack Trace-
at HandyControl.Controls.Window..ctor()
   at HandyControl.Controls.MessageBox..ctor()
   at HandyControl.Controls.MessageBox.CreateMessageBox(Window owner, String messageBoxText, String caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult, String cancelContent, String confirmContent, String yesContent, String noContent)
   at HandyControl.Controls.MessageBox.<>c__DisplayClass44_0.<Ask>b__0()
   at System.Windows.Threading.Dispatcher.Invoke(Action callback, DispatcherPriority priority, CancellationToken cancellationToken, TimeSpan timeout)
   at System.Windows.Threading.Dispatcher.Invoke(Action callback)
   at HandyControl.Controls.MessageBox.Ask(String messageBoxText, String caption)
   at demo.ViewModels.MainWindowViewModel.DeleteIconsMethod() in C:\Users\myusername\source\repos\demo\demo\ViewModels\MainWindowViewModel.cs:line 441
   at Prism.Commands.DelegateCommand.Execute()
   at Prism.Commands.DelegateCommand.Execute(Object parameter)
   at Prism.Commands.DelegateCommandBase.System.Windows.Input.ICommand.Execute(Object parameter)
   at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated)
   at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

image

Activity

  1. NaBian commented on Aug 4, 2020

    @NaBian
    Member

    @ghost1372 can you reproduce this problem?

  2. ghost1372 commented on Aug 4, 2020

    @ghost1372
    Member

    @NaBian
    I tried this over and over again, but nothing happened.
    anyway I will do this again

    @DineshSolanki Please upload your example. It may be related to other code in your project

  3. DineshSolanki commented on Aug 4, 2020

    @DineshSolanki
    Author

    @NaBian @ghost1372 sorry, I forgot to follow up, I noticed that after removing Notification.Show() from my code, the exception disappeared somehow.I think that should be the culprit. As my app was not in version control at that time, I don't have the old code. Just before the messageBox, I used to show the notification.see if it helps, else I'll also try to reproduce again.

  4. DineshSolanki commented on Aug 9, 2020

    @DineshSolanki
    Author

    I tried showing notification again, and it was still working, tried many times, couldn't reproduce, don't know what caused it. We should close this issue for now.

  5. DineshSolanki commented on Nov 2, 2020

    @DineshSolanki
    Author

    Hey, sorry to bother again but while updating the same program today, The exception reappeared multiple times.
    It's happening with the message as well as growinfo -
    here's the stackTrace -

       at HandyControl.Controls.Window..ctor()
       at HandyControl.Controls.MessageBox..ctor()
       at HandyControl.Controls.MessageBox.CreateMessageBox(Window owner, String messageBoxText, String caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult, String cancelContent, String confirmContent, String yesContent, String noContent)
       at HandyControl.Controls.MessageBox.<>c__DisplayClass44_0.<Ask>b__0()
       at System.Windows.Threading.Dispatcher.Invoke(Action callback, DispatcherPriority priority, CancellationToken cancellationToken, TimeSpan timeout)
       at System.Windows.Threading.Dispatcher.Invoke(Action callback)
       at HandyControl.Controls.MessageBox.Ask(String messageBoxText, String caption)
       at FoliCon.ViewModels.MainWindowViewModel.DeleteIconsMethod() in C:\Users\Drona\source\repos\FoliCon\FoliCon\ViewModels\MainWindowViewModel.cs:line 476
       at Prism.Commands.DelegateCommand.Execute()
       at Prism.Commands.DelegateCommand.Execute(Object parameter)
       at Prism.Commands.DelegateCommandBase.System.Windows.Input.ICommand.Execute(Object parameter)
       at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated)
       at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
      Name Value Type
    ◢ $exception {"The type initializer for 'HandyControl.Controls.Window' threw an exception."} System.TypeInitializationException
      ◢ InnerException {Evaluation timed out} System.Exception {System.ArgumentOutOfRangeException}
      Message "Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')" string
      ParamName "index" string
      ▶ TargetSite {Void ThrowArgumentOutOfRange_IndexException()} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
      Message "The type initializer for 'HandyControl.Controls.Window' threw an exception." string
      Source "HandyControl" string
      TypeName "HandyControl.Controls.Window" string

    and here's the method where it happens -

    private void DeleteIconsMethod()
            {
                if (Directory.Exists(SelectedFolder))
                {
                    //TODO: Replace with DialogService if efficient.
                    if (MessageBox.Ask("Are you sure you want to delete all Icons?", "Confirm Icon Deletion") ==
                        System.Windows.MessageBoxResult.OK)
                    {
                        Util.DeleteIconsFromPath(SelectedFolder);
                    }
                }
                else
                {
                    MessageBox.Error("Directory is Empty", "Empty Directory");
                }
            }
  6. ghost1372 commented on Nov 2, 2020

    @ghost1372
    Member

    @DineshSolanki Please copy Method DeleteIconsFromPath codes here

  7. ghost1372 commented on Dec 24, 2020

    @ghost1372
    Member

    Is the problem still there? I could not recreate the problem

  8. DineshSolanki commented on Dec 24, 2020

    @DineshSolanki
    Author

    @ghost1372 its so random, I'm not sure what cause it or make it go away,

  9. DineshSolanki commented on May 19, 2021

    @DineshSolanki
    Author

    I'll close the issue as I haven't encountered it yet again

  10. ghost1372 commented on Nov 10, 2021

    @ghost1372
    Member

    Hi @NaBian
    i have a repro, that crash with this bug here you can test it.

    HandyControl-s-Project.zip

    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions