Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm facing strange problem. I have following code to get last item workflow and its task item.

var wfCol = item.Workflows;
if ((wfCol == null) || (wfCol.Count == 0))
    return null;
var wfItem = wfCol[0];

// this condition is never true when not in debug
if ((wfItem.TaskList != null) && (wfItem.Tasks.Count > 0)) {
....
}

I can never go inside the condition, because wfItem.TaskList is null and wfItem.Tasks throws Object reference not set to an instance of an object.

However, when I use debug and add breakpoint before wfItem.TaskList is called, it will go inside the condition. I have found out that when in VS I disable Property evalution(Tools -> Options -> Debugger -> Enable property evalution) it behaves just like without breakpoint.

Is there any option to force Sharepoint to do the same like Debugger does property evalution?

Thank you

share|improve this question

1 Answer 1

up vote 0 down vote accepted

So here is a nasty hack :-/ I am not proud of it, but it is working. I just called

var tmp1 = wfItem.TaskList;

and

var tmp2 = wfItem.Tasks.Count;

before I really need those properties. So they get loaded and condition is finally correctly evaluated

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.