Could not load type ‘System.Action’ from assembly ‘mscorlib, Version=3.7.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC’.
When porting some code from Silverlight 4 to Windows Phone 7.1, I got an unusual error “Could not load type ‘System.Action’ from assembly ‘mscorlib, Version=3.7.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC’.” – At this bit of code:
Deployment.Current.Dispatcher.BeginInvoke(someMethod);
The code is designed to run “someMethod” on the main UI Thread, so you don’t an illegal cross thread exception.
Invoking Dispatcher.BeginInvoke with a function name like this, is interpreted as an Action, rather than a delegate, so the solution is to use a delegate as follows:
private delegate void someMethodDelegate();
private static void SomeMethodCalledByBackgroundThread()
{
someMethodDelegate action = someMethod;
Deployment.Current.Dispatcher.BeginInvoke(action);
}
Although a little less easy to read, and it appears to have an extra level of indirection, this code works in both SL4 and WP7