c#: Lambda expression is not a delegate type

1 comment
I was changing some code from Silverlight to WPF and ran into this error:
        Cannot convert lambda expression to type 'System.Windows.Threading.DispatcherPriority' because it is not a delegate type
The code was something like this
gui.BeginInvoke(
        ()=>
        {
         Orders = new ObservableCollection<Order>(x);
        }
        ,null
);
The problem is described in detail here:
The article suggests a couple of ways around this, but the best solution in my opinion is found in the comments:
Cast the lambda to an Action explicitly.
It's fast to do, easy and intuitive:
        gui.BeginInvoke(
         (Action)(()=>
             {
                         Orders = new ObservableCollection<Order>(x);
                })
                 ,null
        );
This compiles and runs fine.
Happy holidays
/Henri

1 comment :

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru Dot Net Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete