I am getting the error on the following line for a timer job:
if (listItem["Department"] != null)
Normally this error indicates that it cannot find the field, but there are no spaces and the field label name and strong name are the same. Furthermore, if I write it like this:
if (listItem.Fields["Department"] != null)
I no longer get the error.
The problem is I am trying to call
TaxonomyFieldValueCollection on the object and cannot call it by Fields. Is there some nuanced difference between the two that I'm missing that's causing this error?
EDIT: I figured out the problem. I had set query.ViewFieldsOnly = true; and "Department" was a new field and was not set in the ViewFields, so as far as the timer job could tell the field didn't exist. I simply needed to add the field into the list of fields in ViewField.