Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • mark firth 32 posts 75 karma points
    Jul 05, 2018 @ 13:49
    mark firth
    0

    ContentService Copying e.CancelOperation returns an error in back end

    Hi, Whats is the correct way to cancel a content coping event? I have in my ApplicationStarted event

        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            ContentService.Copying += ContentService_Copying;
        }
    

    and my ContentService_Copying method:

            private void ContentService_Copying(IContentService sender, CopyEventArgs<IContent> e)
        {
            e.CancelOperation(new EventMessage("", "You can not copy", EventMessageType.Error));
        }
    

    If i run the above i then get an error in the backend:

    System.NullReferenceException: Object reference not set to an instance of an object. Stacktrace

    at Umbraco.Web.Editors.ContentController.PostCopy(MoveOrCopy copy)

    at lambda_method(Closure , Object , Object[] )

    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>cDisplayClass10.9(Object instance, Object[] methodParameters)

    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)

    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Controllers.ApiControllerActionInvoker.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.ActionFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Controllers.ActionFilterResult.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.AuthorizationFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.AuthorizationFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Filters.AuthorizationFilterAttribute.

    --- End of stack trace from previous location where exception was thrown ---

    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

    at System.Web.Http.Dispatcher.HttpControllerDispatcher.

    So it looks like the event does get cancelled but i end up with a null reference. So the question is i guess is how do i stop this error bubbling up to the back end UI and replace it with a nicer message? Any ideads anyone?

    cheers,

    Mark

  • ianhoughton 281 posts 605 karma points c-trib
    Oct 03, 2018 @ 13:58
    ianhoughton
    0

    Did you ever get around this issue Mark? I've got the same issue !!

  • mark firth 32 posts 75 karma points
    Oct 04, 2018 @ 10:00
    mark firth
    0

    Hi Ian, No i did not. i worked around the problem and did not cancel the copy. To be honest i think a co-worker actually stopped the action happening in the first place by removing the option via the UI or permissions... I don't really recall.

    Sorry.

    Mark

  • Pagggy 28 posts 71 karma points
    Oct 11, 2018 @ 07:34
    Pagggy
    0

    Hi Mark, I am receiving same error when try to cancel copy event. Do you have any solution for this?

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft