I'm working on a project in which we are upgrading an instance of Sitecore from v6.6 to v8.1. The original code built on top of v6.6 is directly accessing the Sitecore.Data
API (as opposed to Glass Mapper or some other common ORM). I found one strange behavior post-upgrade tied to this snippet of code.
var value = item["Name"];
The field in question was defined by a custom template/field simply named "Name". This is not related to the standard field Name which is actually, to the best of my knowledge, stored as "__Name". From what I could find while running a debugger, the API returns null even though the item in question has a value for that field. In the same debugger session, I explored the contents of the item.Fields
collection and there was no entry for "Name". There were, however, entries for other fields defined by that template. It's as if Sitecore skipped that specific field.
Meanwhile, if I tried to retrieve that field's value via the field definition's GUID, it actually returned the value I was looking for:
var value = item["{64CC3858-18DA-43DA-A7AE-86C1DDEC316D}"];
I can live with this workaround. But for future reference and possibly the benefits of others, are there known field names that should never be used because Sitecore won't retrieve them through normal means? In other words, are there "reserved" field names?
Edit: As it turns out, this ended up being a publishing issue. I don't know how but the field section to which the field in question was a child didn't have any versions and, thus, Sitecore skipped it during publishing. Once I added an English version to that item and republished the entire template, the field and its appropriate value were available from both item["Name"]
and item.Fields["Name"]
. It is strange that using the GUID was a valid workaround in this situation since the field definition item didn't appear to exist in the web database.
Thanks everyone for your help!