5

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?

2 Answers 2

4

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.

1
  • I was afraid this would be the answer, but thanks anyway!
    – Quirijn
    Mar 25, 2014 at 14:49
0

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.

2
  • Not sure how you can use a custom TOM implementation when rendering templates
    – Nuno Linhares
    Mar 25, 2014 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, 2014 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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