The following code is throwing an ArgumentException (Value does not fall within expected range):
var formsList = Web.Current.Lists[MemForms_Constants.MementoForm_LIST_NAME];
var allItemsView = formsList.Views["All Items"];
var allItemsViewFields = allItemsView.ViewFields;
var newMasterField = formTypesList.Fields.GetFieldByInternalName(newMasterInt);
if (null != newMasterField && !allItemsViewFields.Exists(newMasterField.InternalName))
allItemsViewFields.Add(newMasterField);
At this point, I have confirmed that newMasterField is not null. Otherwise, I cannot deduce why it would throw this exception for a new field. I wouldn't expect it to fall in the range of valid values, since it is not there yet. Please let me know if you have any suggestions.
Thanks in advance.