Copied to clipboard

Flag this post as spam?

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


  • Ole Andreas M. Olsen 23 posts 119 karma points
    Mar 04, 2015 @ 22:56
    Ole Andreas M. Olsen
    0

    SaveAndPublishWithStatus from SignalR 2 Hub class

    I'm using SingalR 2 for a chat on my website, but when I call SaveAndPublishWithStatus with raisEvents = false, I still get an Exception "Object reference not set to an instance of an object."

    This is my code

    var _content = ApplicationContext.Current.Services.ContentService.CreateContent(_contentName, folderId, "_contentType");
    ApplicationContext.Current.Services.ContentService.SaveAndPublishWithStatus(_content, 0, false);
    

    Stack trace:

    at Umbraco.Web.NotificationServiceExtensions.SendNotification(INotificationService service, IUmbracoEntity entity, IAction action, UmbracoContext umbracoContext, ApplicationContext applicationContext)
       at Umbraco.Web.NotificationServiceExtensions.SendNotification(INotificationService service, IUmbracoEntity entity, IAction action, UmbracoContext umbracoContext)
       at Umbraco.Core.EnumerableExtensions.ForEach[TItem](IEnumerable`1 items, Action`1 action)
       at Umbraco.Core.Events.TypedEventHandler`2.Invoke(TSender sender, TEventArgs e)
       at Umbraco.Core.Events.EventExtensions.RaiseEvent[TSender,TArgs](TypedEventHandler`2 eventHandler, TArgs args, TSender sender)
       at Umbraco.Core.Services.ContentService.SaveAndPublishDo(IContent content, Int32 userId, Boolean raiseEvents)
       at Umbraco.Core.Services.ContentService.SaveAndPublishWithStatus(IContent content, Int32 userId, Boolean raiseEvents)
    

    The content is published, but it's not in the cache.

    Oops: The documentis published, but not in the cache (internal error)
    

    What am I missing? Seems like SaveAndPublishWithStatus(_content, 0, false) still raises events?

    Edit: I should mention that I'm using Umbraco 7.2.2

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Mar 05, 2015 @ 01:38
  • Ole Andreas M. Olsen 23 posts 119 karma points
    Mar 05, 2015 @ 19:15
    Ole Andreas M. Olsen
    0

    Hi Alex

    The entry on StackOverflow says to use what I already do: Call the function with UserId = 0 and raiseEvents = false. However, I still get the error in SendNotification.

    From StackOverflow:

    Notice that applicationContext.Services.ContentService.Save(content, 0, false); contains two extra paramenters: 0 for the user id (zero is normally the admin user which is always present), and false for specifying that raiseEvents = false.

    Using this approach should ensure that your code doesn't invoke the NotificationService, which then throws an exception.

    I'm already using theese parameters.

  • Ole Andreas M. Olsen 23 posts 119 karma points
    Mar 08, 2015 @ 22:01
    Ole Andreas M. Olsen
    0

    Well. Unable to find out why it sends notification when raiseEvents is set to false, this is my "solution":

                catch (NullReferenceException nre)
                {
                    Log.Error(nre.Message);
                    umbraco.library.RefreshContent();
                }
    
  • Ole Andreas M. Olsen 23 posts 119 karma points
    Mar 12, 2015 @ 21:25
    Ole Andreas M. Olsen
    1

    Ok. This is weird? SaveAndPublishWithStatus sends notifications, but Save does not?

    ApplicationContext.Current.Services.ContentService.SaveAndPublishWithStatus(_content, 0, false); // Throws NullReferenceException
    
    ApplicationContext.Current.Services.ContentService.Save(_content, 0, false); // Is ok!
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies