locked
Receive a "0xC0000005" error code when an event is fired

    Question

  • I am building Windows store App and I am using this class as a base class for all the actions in my MVVM app, I got the "0xC0000005" error somtimes when calling "handler(this, EventArgs.Empty);" in RaiseCanExecuteChanged() method.

    How can I fix this?

    I found this http://support.microsoft.com/kb/811193 but can't figure out how to apply it into my code!

        public class ActionCommand<T> : IActionCommand
        {
            #region Fields
    
            private readonly Action<T> _actionToExecute;
            private readonly Func<T, Boolean> _canExecuteFunction = x => true;
    
            #endregion
    
            #region Constructor(s) and Initialization
    
            /// <summary>
            /// Creates a new ActionCommand instance
            /// </summary>
            public ActionCommand()
                : this(null, null)
            {
            }
    
            /// <summary>
            /// Creates a new ActionCommand instance
            /// </summary>
            /// <param name="actionToExecute">The action to be executed</param>
            public ActionCommand(Action<T> actionToExecute)
                : this(actionToExecute, null)
            {
            }
    
            /// <summary>
            /// Creates a new ActionCommand instance
            /// </summary>
            /// <param name="actionToExecute">The action to be executed</param>
            /// <param name="canExecuteFunction">The function to invoke to check if execution is allowed</param>
            public ActionCommand(Action<T> actionToExecute, Func<T, Boolean> canExecuteFunction)
            {
                if (actionToExecute != null) _actionToExecute = actionToExecute;
                if (canExecuteFunction != null) _canExecuteFunction = canExecuteFunction;
            } 
    
            #endregion
    
            #region IActionCommand Implementation
    
            /// <summary>
            /// Defines the method to be called when the command is invoked.
            /// </summary>
            /// <param name="parameter">Data used by the command. If the command does not require data to be passed, this object can be set to null.</param>
            public void Execute(Object parameter)
            {
                try
                {
                    if (!CanExecute(parameter)) return;
                    if (_actionToExecute != null) _actionToExecute((T)parameter);
                    Executed(this, EventArgs.Empty);
                }
                catch (Exception ex)
                {
                    ServiceFactory.Instance.ApplicationServices.SendError(ex.Message, "ActionCommand,Execute");
                }
            } 
    
            /// <summary>
            /// Defines the method that determines whether the command can execute in its current state.
            /// </summary>
            /// <param name="parameter">Data used by the command. If the command does not require data to be passed, this object can be set to null.</param>
            /// <returns><c>true</c> if this command can be executed; otherwise, <c>false</c>.</returns>
            public Boolean CanExecute(Object parameter)
            {
                return _canExecuteFunction == null || _canExecuteFunction((T)parameter);
            }
    
            /// <summary>
            /// Occurs when changes occur that affect whether or not the command should execute.
            /// </summary>
            public event EventHandler CanExecuteChanged;
    
            /// <summary>
            /// Raises the <see cref="CanExecuteChanged"/> event
            /// </summary>
            public void RaiseCanExecuteChanged()
            {
                try
                {
                    var handler = CanExecuteChanged;
                    if (handler != null)
                    {
                        handler(this, EventArgs.Empty);
                    }
                }
                catch
                {
                    //ServiceFactory.Instance.ApplicationServices.SendError(ex.Message, "ActionCommand,RaiseCanExecuteChanged");
                }
            }
    
            public event EventHandler Executed = delegate { };
    
            #endregion
        }


    Tariq

    Friday, March 06, 2015 1:57 PM

All replies

  • FatalExecutionEngineError was detected
    Message: The runtime has encountered a fatal error. The address of the error was at 0x722c34b0, on thread 0x1a4. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

    Tariq

    Friday, March 06, 2015 3:56 PM
  • you can post your error to Microsoft connect, it likes a platform error. http://connect.microsoft.com/
    Friday, March 13, 2015 2:00 AM
  • Hi Tariq,

    The cause of the problem is obscure, thus we cannot provide useful information. So it’s recommend to narrow down this issue to find out which code cause this problem. You can try comment some code snippets one by one to check where will throw that exception.

    If you don’t know how to do, can you submit a mini repro project on your OneDrive and share a link here. I can try it on my side to see if the problem is persists.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 18, 2015 5:29 AM
    Moderator