Operation is not valid due to the current state of the object

Feb 7, 2010 at 7:49 PM
Edited Feb 8, 2010 at 4:16 PM


Sometimes, intermittently, I get this InvalidOperationException error:

System.InvalidOperationException was unhandled
  Message="Operation is not valid due to the current state of the object."
       at IronCow.TaskListTaskCollection.SmartResync()
       at IronCow.TaskList.get_Tasks()
       at SyncMyMilk.RTMHelper.<Test>d__0.MoveNext() in G:\Projects\Temp\RTMTest\MyForm\RTMHelper.cs:line 108
       at SyncMyMilkForm.Form1.listView1_SelectedIndexChanged(Object sender, EventArgs e) in G:\Projects\Temp\RTMTest\MyForm\Form1.cs:line 94
       at System.Windows.Forms.ListView.OnSelectedIndexChanged(EventArgs e)

The Test() method is:

    public IEnumerable<Task> Test(string taskList)
foreach (Task t in Rtm.TaskLists[taskList].Tasks)
yield return t;

I also get this InvalidOperationException when doing a simple 

string s = Rtm.TaskLists[0].Tasks[0].Name;

What am I doing wrong?


I just compiled and ran with the IronCow source code, it bombs on the string.IsNullOrEmpty(mList.Filter line in SmartResync()

        internal void SmartResync()
if (!mList.GetFlag(TaskListFlags.Smart))
throw new InvalidOperationException();
if (string.IsNullOrEmpty(mList.Filter))
throw new InvalidOperationException();




Feb 8, 2010 at 3:50 PM


You're not doing anything wrong as far as I can tell... It's most probably a bug in IronCow but I can't quite figure out what could be causing it.

Basically, what's happening is that the list from which you're pulling the tasks is a "smart list" (it has the "Smart" flag), but has no search query (filter) set. Smart lists in RTM are basically "live searches", where the list contains tasks that comply to a filter... which seems to be empty. Could you check that the task list you're iterating on is, indeed, a smart list with a non-empty filter?