Why does i have this error and how to fix it. Thanks for help
Error 4 Cannot convert lambda expression to type ‘System.Delegate’ because it is not a delegate type
void provider_GetAssignmentsComplete(object sender, QP_Truck_Model.Providers.GetAssignmentsEventArgs e) {
lvMyAssignments.Dispatcher.BeginInvoke(() =>
{
lvMyAssignments.ItemsSource = e.HandOverDocs;
});
}
Lambda expression are not implicitly convertible to delegates in certain cases. Specifically, if the method expects the type
Delegateyou have to first explicitly cast the lambda for the compiler to accept it.What you can do is explicitly cast the lambda, which should allow you to use
BeginInvoke:Normally, if you have a method with a strongly-typed delegate signature, like:
The compiler can convert a lambda expression to the appropriate delegate signature needed. But if the method is loosely typed:
the compiler will not accept a lambda. You can, however, cast the lambda expression to a specific delegate signature (say Action), and then pass that to the method. The compiler cannot automatically do this for you, because there are many different delegate types that could be a valid match for the signature of the lambda … and the compiler has no way of knowing which would be the right one.