views:

81

answers:

2

I can't figure out what Re# is complaining about with a piece of code. Everything compiles ok and works as it should, but Re# can't seem to resolve the expression without offering any suggestions. Look at the attachment for code and error.

Any offers?

alt text

+1  A: 

I haven't used Resharper so I could be off the mark here, but Invoke accepts a Delegate or an Action; a lambda expression can be converted to either of those (as explained in this answer from Jon Skeet). Perhaps Resharper doesn't know which of those it should be cast to.

If you change it to

Dispatcher.BeginInvoke(new Action(() => // ...

the error will most likely go away.

Mark Rushakoff
nice try, but Action requires a type parameter like Action<T>. What is T here?
danijels
@danijels: It only requires a parameter in .NET 2.0; 3.5+ include the [Action](http://msdn.microsoft.com/en-us/library/system.action.aspx) type without the parameter. You can obtain the plain Action by using [LinqBridge](http://code.google.com/p/linqbridge/), or you can use a MethodInvoker as described in [this answer from Marc Gravell](http://stackoverflow.com/questions/253138/anonymous-method-in-invoke-call/253150#253150).
Mark Rushakoff
I still can't get it to satisfy Re#. Your suggestion will compile just as fine as the original code, but Re# still pops up asking me to include the type parameter. I should also mention this is VS2010 and a Silverlight 4 project.
danijels
It was an educated guess. I'm going to mark the answer as CW because it's still relevant to the discussion, but it's not *the* answer to the question.
Mark Rushakoff
+1  A: 

Your code is fine. This was a bug in Resharper, now fixed in version 5.1.

Had the same warning all over the place (to the extent I turned off Re# until I got the 5.1 update). Ours was also a Silverlight 4 app.

Re# 5.1 behaves a lot better with VS 2010 now. Clashes with intellisense autocomplete have also vanished.

Enough already