Copied to clipboard

Flag this post as spam?

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


  • Umbraco 137 posts 294 karma points
    Dec 10, 2012 @ 14:58
    Umbraco
    0

    Upgraded to 4.11.1, ApplicationBase no longer constructed, thus event handlers not added

    Usually all assemblies are scanned looking for classes imheriting from umbraco.BusinessLogic.ApplicationBase. But it seems after upgrading this is no longer the case. Can someone confirm or deny this?

    Is there a straight-forward way to re-enable an exisiting ApplicationBase class and thus its event handlers?

    Thanks!

  • Umbraco 137 posts 294 karma points
    Dec 10, 2012 @ 15:23
    Umbraco
    0

    I see that ApplicationBase is marked [Deprecated] but its IntelliSense still indicates fully automatic discovery and initialization.

    Also, the release documentation lists a breaking change related to a custom Global.asax, except my solution was not using a custom Global.asax. I personally was not aware of the link between Global.asax and ApplicationBase.

    It should be noted (preferably on the release page) that any code that relies on automatic discovery of ApplicationBase classes will break in 4.9 and later (silently), and that a common scenario for this is encountered when using Umbraco event handlers.

    Thanks!

  • Jeff 17 posts 38 karma points
    Dec 13, 2012 @ 00:02
    Jeff
    0

    "any code that relies on automatic discovery of ApplicationBase classes will break in 4.9 and later (silently), and that a common scenario for this is encountered when using Umbraco event handlers"

    I'm just learning this today after beating my head repeatedly for about 2 hours wondering why I cannot get an AfterPublish event to fire in 4.9.1.

    Did you find a way to tie into events otherwise? My boss bought me a subscription to Umbraco.tv, which shows a deprecated way of tying into an event. This is the first video I've watched on Umbraco.tv, and being as they're selling outdated / incorrect information, I'm suggesting he ask for a refund.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 13, 2012 @ 00:41
    Tom Fulton
    0

    Hi,

    In 4.9 (?) it was changed to:  umbraco.businesslogic.ApplicationStartupHandler - if you just change your classes to inherit from this it should work fine.

    Also, noticing that 4.11.1 it might have been changed again to Umbraco.Web.IApplicationEventHandler

    -Tom

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Dec 13, 2012 @ 09:06
    Sebastiaan Janssen
    0

    It was "changed" but ApplicationBase is not removed yet, just obsoleted. 

    Documentation: http://our.umbraco.org/documentation/Reference/Events/

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Dec 13, 2012 @ 09:07
    Sebastiaan Janssen
    0

    AfterPublish event example:

    using System.Linq;
    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic.web;
    
    namespace Umbraco.Extensions.EventHandlers
    {
        public class LogMe : ApplicationBase
        {
            public LogMe()
            {
                Document.AfterPublish += DocumentBeforePublish;
            }
    
            static void DocumentBeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
            {
                Log.Add(LogTypes.Debug, -1, "Does it work?");
            }
        }
    }
  • Umbraco 137 posts 294 karma points
    Dec 13, 2012 @ 09:11
    Umbraco
    0

    I have already changed my code to use the new interface, but before that I had a similar class, and it was no longer constructed after upgrading. Same goes for Jeff I presume from his post, @Jeff can you confirm?

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Dec 13, 2012 @ 09:33
    Sebastiaan Janssen
    0

    Here's a tiny example project, build it and put the resulting dlls in a v491 install, then publish. 

    Query the log afterwards: select top 100 * from umbracoLog order by id desc

    You should see a "Does this work?" entry in your logs.

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Dec 13, 2012 @ 09:34
  • Jeff 17 posts 38 karma points
    Dec 13, 2012 @ 17:11
    Jeff
    0

    @Michiel, this is from a fairly recent fresh install of 4.9.1, rather than an upgrade, but yes, the same problem in that I'm not able to get into the constructor.

    @Sebastiaan, I imported the assembly built from your example, recycled my app pool, went back to the Umbraco Back Office, republished my home page and all its subpages, and queried the log table. I didn't see any logs that said 'does this work nor my log message, and running "select top 100 * from umbracoLog where logComment like '%Does this work%' order by id desc" returns 0 results.

    @Tom, I've tried inheriting from both classes to no avail.

    The following is my code. Sorry for poor format, I couldn't get manual html "code" tag nor "preformatted" to work out for me. I've included comments to note other attempts as well. :

    using System;
    using System.Text;
    using SolrSearch;
    using umbraco.BusinessLogic;
    using umbraco.businesslogic;
    using umbraco.cms.businesslogic;
    using umbraco.cms.businesslogic.web;
     
    namespace VVF.Web
    {
        //public class SaveToSolr : ApplicationStartupHandler
        public class SaveToSolr : ApplicationBase
        {
            public SaveToSolr()
            {
                Console.WriteLine("Constructor Entered");
                //Document.AfterPublish += new Document.PublishEventHandler(DocumentAfterPublish);
                Document.AfterPublish += DocumentAfterPublish;
            }
            
            //public static void DocumentAfterPublish(Document sender, PublishEventArgs args)
            static void DocumentAfterPublish(Document sender, PublishEventArgs args)
            {
                Log.Add(LogTypes.Publish, 0, "after publish log");
            }
        }
    }

     

    My console never shows that the constructor was entered. I've tried placing this file in the "App_Code" directory, as well as just having it in a directory in my project. Anyone see anything I may be missing?

    Thanks!

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Dec 13, 2012 @ 17:24
    Sebastiaan Janssen
    0

    @Jeff does it work when you just publish one page? I'm not sure if republish all kicks of the same events (though it seems like it should).

  • Jeff 17 posts 38 karma points
    Dec 13, 2012 @ 17:32
    Jeff
    0

    @Sebastiaan it did not. I just tried publishing by right-click and publish a page, and also by using 'save and publish' to no avail. The following is my log:

    iduserIdNodeIdDatestamplogHeaderlogComment
    6992-12012-12-13 09:29:39.323DebugXml saved in 00:00:00.0038235
    6980-12012-12-13 09:29:39.267DebugCloning ended...
    6970-12012-12-13 09:29:39.267DebugCloning...
    6960-12012-12-13 09:29:39.263SystemLoading content from disk cache...
    695210582012-12-13 09:29:39.213Publish
    694210582012-12-13 09:29:39.120Save
    693210582012-12-13 09:29:36.617Open

     

    No errors or anything, so looks like everything went through fine and all.

  • Jeff 17 posts 38 karma points
    Dec 14, 2012 @ 18:25
    Jeff
    0

    This morning I removed Umbraco from the project and replaced it with a fresh download of 4.9.1, in case something had changed with my assemblies somehow. Still having the same issue; nothing is stored in the log and the debugger does not go into any breakpoints I've set in the AfterPublish events.

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Dec 15, 2012 @ 06:58
    Richard Soeteman
    0

    Hey Guys,

    I'm using ApplicationBase in all of my packages and it works from 4.7 to 4.11.1. The only difference is that I'm using a DLL instead of putting the code in app_code or any other folder. Maybe that helps?

    Cheers,

    Richard

  • Umbraco 137 posts 294 karma points
    Dec 15, 2012 @ 13:47
    Umbraco
    0

    @Richard

    My ApplicationBase class was in a separate class library project as well, but it definitely did not get called after I upgraded Umbraco.

    I haven't had time to go back to the code that wasn't working. And I'm just glad that it's working now, so I might never (it's quite a complex solution). I just wanted to point out that there is an (edge) case where it doesn't seem to work as described.

  • Edwin van Koppen 156 posts 270 karma points
    Jan 18, 2013 @ 12:02
    Edwin van Koppen
    0

    If got this:

    public class AppEvents : IApplicationEventHandler {
            public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext) {

            }
            public void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext) {
                Document.AfterPublish += DocumentEvents.Document_AfterPublish;
                Document.AfterSave += DocumentEvents.Document_AfterSave;
            }
            public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext) {
            }

    }

    But it get called twice every time.. if i put a debugger on it, also two hits. Anybody also got this problem? i use 4.11.2

     

     

  • Murray Roke 503 posts 966 karma points c-trib
    May 23, 2013 @ 07:38
    Murray Roke
    0

    I have the same issue in 4.11.8 in that ApplicationBase objects not constructed.

    Funny thing is I have 6 of them, 3 are constructed, and 3 are not.

    I tried implementing some that didn't get constructed as IApplicationStartupHandler instead, which also didn't work, 

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    May 28, 2013 @ 08:21
    Peter Gregory
    1

    @Murray make sure that your classes containing the event registrations are public otherwise they will not be picked up during initialisation.

  • Murray Roke 503 posts 966 karma points c-trib
    May 29, 2013 @ 07:06
    Murray Roke
    0

    Thanks Pete, sorted. This caught me out because I was upgrading a site, and the previous version of umbraco didn't require them to be public.

Please Sign in or register to post replies

Write your reply to:

Draft