Delving into v4 events and can't seem to get them working!
Here is my code, I'm expecting to see some log entries but am not getting any...
[code]
using System;
using umbraco.cms.businesslogic.media;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic;
using umbraco.BusinessLogic;
namespace FergusonMoriyama.xxx
{
class xxx: umbraco.BusinessLogic.ApplicationBase
{
public xxx()
{
Media.New += new Media.NewEventHandler(mediaAfterNew);
Document.New += new Document.NewEventHandler(documentnew);
}
No it should be working (at least in v4.0.1). And Haven't tried the events you are using. What I always try first is setting a breakpoint on the event handlers to see if they get hit. Maybe an exception is thrown and you won't see that.
Have you testet your code in umbraco 4.5? I'm having a similar issue after having upgraded from 4.0 (.Net 2.0) to 4.5 (.Net 4.0). My code is the following which worked well in 4.0:
using System;
using umbraco;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
///<summary>
/// UmbracoNewsHandler handles events that are related to the Umbraco News
I've encountered these issues as well (4.5 & 4.5.1) Tried subscribing to Member_New, Member_AfterNew and Member_Delete .. none of them seems to fire. The constructor in the document inheriting from ApplicationBase does not seem to be executed either.
That is the exact same issue I'm experiencing. The constructor in the class inheriting from ApplicationBase does not seem to get executed. And this is only an issue with the code in v4.5.
Good to hear I'm not the only one experiencing this. Has anyone reported this issue on codeplex? (otherwise I'll do it :)) It's quite a showstopper for the project I'm working on.
Well I'm glad too to hear that I'm not the only one with the issue either, as I just cannot see what I'm doing wrong! I have reported the issue to Tim who is looking into my specific issue but I haven't reported it on codeplex. But please do so :) It is a show stopper for me as well and I would like to update my News package for others to use in v4.5
I have tried to add the eventhandler in a Class Library, compiled it and added it to the project (/bin) which resulted in the events being hooked up correctly.
So the error only affects ActionHandlers written directly in the App_Code folder - not precompiled Class Libraries.
I am just new to this but I found my events fired but I could not debug them until I put them in a separate project. Probably a better architecture anyway perhaps?
Getting events working in v4?
All,
Delving into v4 events and can't seem to get them working!
Here is my code, I'm expecting to see some log entries but am not getting any...
[code]
using System;
using umbraco.cms.businesslogic.media;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic;
using umbraco.BusinessLogic;
namespace FergusonMoriyama.xxx
{
class xxx: umbraco.BusinessLogic.ApplicationBase
{
public xxx()
{
Media.New += new Media.NewEventHandler(mediaAfterNew);
Document.New += new Document.NewEventHandler(documentnew);
}
void mediaAfterNew(Media sender, NewEventArgs e)
{
Log.Add(LogTypes.Debug, sender.Id, "Hello world");
}
void documentnew(Document sender, NewEventArgs e)
{
Log.Add(LogTypes.Debug, sender.Id, "Hello world");
}
}
}
[/code]
Are there any additional steps beyond placing my DLL in the bin directory that need to be considered?
Thanks!
Hi Darren,
No it should be working (at least in v4.0.1). And Haven't tried the events you are using. What I always try first is setting a breakpoint on the event handlers to see if they get hit. Maybe an exception is thrown and you won't see that.
Hope it helps you,
Richard
sorry, silly mistake.
my constructor wasn't marked public!
Hi Darren,
Have you testet your code in umbraco 4.5? I'm having a similar issue after having upgraded from 4.0 (.Net 2.0) to 4.5 (.Net 4.0). My code is the following which worked well in 4.0:
using System;
using umbraco;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
/// <summary>
/// UmbracoNewsHandler handles events that are related to the Umbraco News
/// </summary>
///
namespace umbraco.appstract
{
public class UmbracoNewsItemHandler : ApplicationBase
{
public UmbracoNewsItemHandler()
{
Document.New += new Document.NewEventHandler(Document_New);
//umbraco.cms.businesslogic.web.Document.New += new umbraco.cms.businesslogic.web.Document.NewEventHandler(Document_New);
umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, "The eventhandlers are attached");
}
/// <summary>
/// Event handler for new news pages
/// </summary>
/// <param name="sender">The newly created document</param>
/// <param name="e"></param>
public void Document_New(umbraco.cms.businesslogic.web.Document sender, umbraco.cms.businesslogic.NewEventArgs e)
{
umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, "The eventhandler Document_new is fired");
}
}
}
I've encountered these issues as well (4.5 & 4.5.1)
Tried subscribing to Member_New, Member_AfterNew and Member_Delete .. none of them seems to fire. The constructor in the document inheriting from ApplicationBase does not seem to be executed either.
/Simon
Hi Simon,
That is the exact same issue I'm experiencing. The constructor in the class inheriting from ApplicationBase does not seem to get executed. And this is only an issue with the code in v4.5.
Are anybody experiencing the same issues?
/Kim
Hi Kim,
Good to hear I'm not the only one experiencing this. Has anyone reported this issue on codeplex? (otherwise I'll do it :))
It's quite a showstopper for the project I'm working on.
/ Simon
Hi Simon,
Well I'm glad too to hear that I'm not the only one with the issue either, as I just cannot see what I'm doing wrong! I have reported the issue to Tim who is looking into my specific issue but I haven't reported it on codeplex. But please do so :) It is a show stopper for me as well and I would like to update my News package for others to use in v4.5
/Kim
Hi Simon,
I have created the CP issue. I'll update if I find a solution before that.
/Kim
Okay, I created a similar issue yesterday. ;)
http://umbraco.codeplex.com/workitem/28514
Hi Simon
I have tried to add the eventhandler in a Class Library, compiled it and added it to the project (/bin) which resulted in the events being hooked up correctly.
So the error only affects ActionHandlers written directly in the App_Code folder - not precompiled Class Libraries.
This should solve your issue as well I hope :)
Cheers,
Kim
Hi Kim,
Yes it did - Niels also mentioned the same solution on twitter, but I forgot all about posting the solution in here, but thanks for testing it out!
Have a great weekend :)
I am just new to this but I found my events fired but I could not debug them until I put them in a separate project. Probably a better architecture anyway perhaps?
is working on a reply...