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?
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.
"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.
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
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?
@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);
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?
@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
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.
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?
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.
public class AppEvents : IApplicationEventHandler { public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext) {
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!
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!
"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.
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
It was "changed" but ApplicationBase is not removed yet, just obsoleted.
Documentation: http://our.umbraco.org/documentation/Reference/Events/
AfterPublish event example:
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?
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.
Oops, link: https://dl.dropbox.com/u/3006713/UmbracoEventHandler491.zip
@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. :
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!
@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).
@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:
No errors or anything, so looks like everything went through fine and all.
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.
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
@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.
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
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,
@Murray make sure that your classes containing the event registrations are public otherwise they will not be picked up during initialisation.
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.
is working on a reply...