This project is read-only.

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

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

Hi.

Sometimes, intermittently, I get this InvalidOperationException error:

System.InvalidOperationException was unhandled
  Message="Operation is not valid due to the current state of the object."
  Source="IronCow"
  StackTrace:
       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?

 EDIT:

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();

 

/M 

 

Feb 8, 2010 at 4:50 PM

Hey,

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?

Thanks,