I've seen a couple of threads about this on the Internet, but I feel like none of them apply to my situation... Either that, or I just simply haven't understood a thing from them (which is likely).
The thing is: I'm writing a test for a converter method, that "converts" an Enum to an appropriate SolidColorBrush.
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Brush result = new SolidColorBrush(Colors.White); if (value != null) { switch ((InstallationStatus)value) { case InstallationStatus.Draft: result = new SolidColorBrush(Colors.DarkGray); break; case InstallationStatus.Ready: result = new SolidColorBrush(Colors.Green); break; case InstallationStatus.Uploaded: result = new SolidColorBrush(Colors.Orange); break; case InstallationStatus.Error: result = new SolidColorBrush(Colors.Red); break; default: break; } } return result; }
It works just fine on its own, when called from the app's view. I also have a test method, that basically does this:
InstallationStatusBrushConverter converter = new InstallationStatusBrushConverter(); object result = converter.Convert(null, null, null, null);
The test method calls Convert, which tries to instantiate the result field, but the UnauthorizedAccessException gets thrown... Does anyone have an idea of what's going on here?
System.UnauthorizedAccessException: Invalid cross-thread access.
? – kennyzxresult = Brushes.Red
. – Chris DunawayBrushes
class in WP, also there are no GDI handles in WP. It's quite safe to create new Brushes. :) – yasen