Monday, April 21, 2008

Cannot convert anonymous method to System.Predicate message may be misleading

This compiler report is misleading. It turned out that there was an undeclared variable within anonymous method, e.g. "someId" below was not declared or passed in as an argument. It looks like the compiler may not be able to dig deeper into the anonymous method and report syntax or normal errors.

if(delegate(Product rcrd) { return (rcrd.ItemId.Equals(someId); }))

{

// do something
}


Check out the following links for more info:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=91434
http://weblogs.asp.net/avnerk/archive/2006/05/22/Bad-compiler-warnings-when-using-anonymous-methods-for-Predicate_3C00_T_3E00_.aspx

0 comments: