Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

We are busy upgrading 2009 to 2011 and found an annoying difference between the TOM.Net API for both versions. If you try to create a TcmUri object with the single-argument constructor, and the value of the argument is null, the behavior is different:

// 2009
TcmUri uri = new TcmUri(null);
log.Debug("found uri " + uri.ToString());
// the log shows 'found uri tcm:0-0-0'


// 2011
TcmUri uri = new TcmUri(null);
// the code breaks here with exception 'Null is not allowed'
log.Debug("found uri " + uri.ToString());

Of course, we don't pass 'null' on purpose. But we have many situations where we configure a uri through a package variable. When the variable isn't in the package, we end up with the null value.

Did anyone encounter the same problem? If so, how did you solve it?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

I thought the argument was always required. I guess it didn't always validate it correctly.

Anyway, you could check for null or TcmUri.IsValid before trying to parse it and use a default value of TcmUri.UriNull if you want it to work the same as before. That does require code changes but I don't see any way around that.

share|improve this answer
    
I was afraid this would be the answer, but thanks anyway! –  Quirijn Mar 25 at 14:49

To handle all types of TcmUri issues, we have our own TcmUri class which handles

  • NullUri's
  • Implicit Operators

You can view @Rob code at TcmUri.cs.

share|improve this answer
    
Not sure how you can use a custom TOM implementation when rendering templates –  Nuno Linhares Mar 25 at 14:42
    
Thanks Siva. I would rather not re-do so much of SDL's own code. In my case (where I have access to the Tridion libraries) it would be more effective to have a wrapper class instead. –  Quirijn Mar 25 at 14:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.