I am trying to migrate a set of list columns to managed metadata columns. As part of this process, I have created a set of metadata columns parallel to the existing list columns, suffixed with the letter 'M'. I get references to the term store and term I wish to set, but when calling TaxonomyField.setFieldValue(), SharePoint hangs. The relevant parts of the code are given below. If this is relevant, this specific code is run through the debugger in the Page_Load event handler of an applciation page.
SPList l = web.Lists["Testlib"];
TaxonomySession oSession = new TaxonomySession(SPContext.Current.Site);
TermStore oTermStore = oSession.TermStores["Metadata Service Application Proxy"];
Group oGroup = oTermStore.Groups["Reports"];
TermSet years = oGroup.TermSets["Year"];
foreach (SPListItem i in l.Items)
{
// If year non-null, move value from Year to YearM
if (i["Year"] != null) {
string index = i["Year"].ToString();
Term thisYear= years.Terms[index];
TaxonomyField oField = (TaxonomyField)i.Fields["YearM"];
web.AllowUnsafeUpdates = true;
oField.SetFieldValue(i, thisYear); // Sharepoint hangs here
web.AllowUnsafeUpdates = false;