Stupid Mistakes: Tridion Event System and Async Subscriptions

It’s easy to make one of those simple and stupid mistakes when developing with Tridion.  You know, one of those mistakes that make you lose an hour or more to debugging.  One of those mistakes that, after realizing what you did wrong, you are extremely happy you found the issue, but at the same time still just a bit embarrassed that you missed it in the first place.  I thought I’d share one that I made over the weekend in hopes that perhaps if someone else accidently went down the wrong path they’d quickly be able to correct themselves.

Over the weekend I was working on some Event System code that worked with Multimedia Components.  I’ll spare most of the details, but the code had to do two main things: 1.) Get the binary data out of the Multimedia Component and 2.) Set a Metadata Field to a value if the field was empty.  Pretty easy right?  We’ve all done these things before and this kind of functionality should be smooth sailing.  Until its not…

Coded. Deployed. Created a new Multimedia Component.  Save and Closed.  And… wth? The Event Log showed the following error.

A database error occurred while executing Stored Procedure "EDA_ITEMS.GETBINARYCONTENT".
ORA-01403: no data found
ORA-06512: at "TRIDION_CM.EDA_ITEMS", line 4100
ORA-06512: at line 1

Looks like my code didn’t like my call to the GetByteArray() method… weird. This portion of the Event System was using the Processed event phase. Interestingly, switching it to Initiated made the error go away. Shouldn’t be a solution, but hey, it was working now. I’ll move on and figure out the root issue later.

Next I added code to set the Metadata Field when it was null. Coded. Deployed. Saved and Closed the modified MM component. And… wth again? The Event Log now showed the following error.

The item tcm:123-4567-16-v0 does not exist.

Another piece of code I’ve done countless times… why is it failing now?  Tridion, why have you forsaken me!?!

The Issue

After much debugging and even coming up with a workaround to get my code working, I looked up at the piece that was subscribing my event and immediately face palmed.

EventSystem.SubscribeAsync<Component, SaveEventArgs>(OnComponentSaveInitiated, EventPhases.Initiated);

Can you see the issue above? Yep, I had subscribed my event asynchronously, and those weird issues I was seeing was the price I paid for doing it incorrectly.  For those of you who are not familiar with the Tridion Event System, you should only subscribe events asynchronously via the SubscribeAsync method with a TransactionCommitted phase.

What had happened was, when I started on this Event Handler, I had a different set of requirements. I was originally going to use a TrasnactionCommitted phase and a Check In event, and started coding it, but switched to the Initiated phase with a Save event once I got the updated requirements. Unfortunately, I forgot to change the subscription method to not subscribe asynchronously.

EventSystem.Subscribe<Component, SaveEventArgs>(OnComponentSaveInitiated, EventPhases.Initiated);

Ah, all better now…

Another Clue…

Another clue that I had used the wrong subscription method should have been the errors themselves. Normally when an Exception is thrown in the Initiated or Processed phase, that error prevents the save, and the error message is displayed to the user. With my code, the component was saving just fine, and the error message was only getting logged and not communicated to the user.

Tridion Area51 Notifications

If you haven’t yet signed up to commit to the dedicated Tridion StackExchange site and are interested in supporting it, you should do that now. You can read more about the goals we need to reach in my previous post.

If you are interested in getting notifications and updates regarding the status of the dedicated Tridion site, a fellow Tridionaught, Chris Summers, is putting together an e-mail list. You can sign up for it over on the Tridion Developer site.

We are getting closer! In my last post, we were at 75% of the commitment score goal and needed 4 more people committed who had 200 rep on any of the sites. Today as of this post, we have the 100 people with 200 rep required, and are at 84% of reaching the commitment goal. Nice work everyone!

Tridion Area 51 Site Proposal

When I first started with Tridion, I remember wishing that there was more places than just the forums to look for information and help on Tridion (and maybe it was just my own greenness that overlooked anything that was actually out there beyond the forums during that time). Today its a different case, do a quick Google search for what you are looking for and you should come across Tridion related blogs and Q&A sites. One of those Q&A sites you’ve most likely stumbled upon is the Stack Overflow site and the Tridion tag. And if you haven’t heard, there’s a proposal for a dedicated Tridion site in the StackExchange system (you know, that Area 51 banner you see on most of the Tridion blogs and various posts and comments asking for your help by committing to the site?). That’s right, a dedicated StackExchange just for SDL Tridion where you can go to get help on your Tridion related questions. At the time of this writing, our commitment stats to reach our goals for this site look like:


Commitment Goals for Tridion Area 51

Currently we’re in our Commitment goal, which means before the site is even created, StackExchange needs to know that the site will have enough people that will be using it. The first goal, having 200 committers in total, has been reached (with a total of 251 so far!). The second goal, having 100 of those committers that have a total reputation score of 200 or more on any Stack Exchange site, we are just around the corner of reaching with a total of 96 (just 4 more to go!). The third goal is the tricky one, the committment score. This score is calculated based on all the users’ reputation and activeness on other sites. There’s also a decay factor involved, meaning that you should revisit the Area 51 page once in awhile to renew your vote.

What can I do to help?

  • If you have not done so already, commit to the Tridion Area 51 Site Proposal.
  • If you do not have a reputation of 200 on any of the Stack Exchange sites, try to achieve this. You can gain rep not only by answering questions, but by asking them as well! Start asking, answering and voting on questions and answers on the StackOverflow Tridion Tag.
  • Even if you don’t have anything you want to ask or answer, start voting for the questions and answers that you found useful. This may not increase your rep score, but could push another member’s score and help raise the Commitment Score.
  • Having a rep of 200 or more on multiple sites also helps! Start asking and answering away on other sites that interest you.
  • Don’t let your vote decay! If you haven’t visited the Area 51′s Tridion page in awhile, make sure to login and visit the page!

As a reminder, visit this page to see how the Commitment Score is calculated.

Thanks everyone for your help, and I hope to be seeing you on our own dedicated Tridion site soon!

Tridion Dreamweaver Template Delimiter Escaping

This was a question that popped up in the forums recently, so I thought I would share on how to escape Dreamweaver delimiters. That is, actually outputting “@@someValue@@” or “${someValue}” in your DWT’s without having them parsed.

The following samples will all escape the delimiters properly.

@@"@" + "@" + "test" + "@" + "@"@@
@@"$" + "{" + "test" + "}"@@
@@"@" + "@test@" + "@"@@
@@"$" + "{test}"@@

And will output:

@@test@@
${test}
@@test@@
${test}

As a side note, trying to escape the delimiters using the “${ }” delimiter will not work the same. The closest I got to actually displaying the correct output was by using ${"$" + "{" +"test}}. Yep, the odd number of quotes was needed… if you add the last quote (as it looks like it should need), it’ll actually output the last quote. Odd, no?

I hope that helps anyone who’s in need to do this sort of escaping from their DWT’s!

Redeploying a Tridion 2011 Event System DLL

Ever have a problem with redeploying your Tridion 2011 Event System DLLs and keep getting a “File In Use” error? Even after shutting down the Tridion COM package, recycling the SDL Tridion application pool, and shutting down the related Tridion services? Normally on a small development team (or working by yourself on the Tridion instance) you won’t run into this issue if you follow the normal steps outlined in the documentation. But if you are working on a large project (with lets say 50+ concurrent Tridion users), you might of run into this little frustrating situation of trying to hunt down all the processes that have your file locked.

Here’s a quick and easy trick you can do to get around this issue, and its easier than having to ensure that everything is shut down first.

  1. Rename the existing DLL on the server.  For example, rename Tridion.Sample.EventSystem.dll to Tridion.Sample.EventSystem.dll_OLD.  Even though it is in use, you still have the power to rename it.
  2. Copy your updated DLL to the server.
  3. Restart the Tridion COM+ package.
  4. Restart the Tridion Publisher service.
  5. Recycle the IIS SDL Tridion 2011 application pool.
  6. Delete the old renamed DLL when you get the chance.