static private void UpdateField <T>(FieldInfo fi, T target, UPnPService service) where T : DispatcherObject, IUPnPServiceCallback { try { object stateVariable = Convert.ChangeType(service.QueryStateVariable(fi.Name.Substring(1)), fi.FieldType, CultureInfo.InvariantCulture); if (String.CompareOrdinal(stateVariable.ToString(), "NOT_IMPLEMENTED") != 0) { target.Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart) delegate { target.StateVariableChanged(service, fi.Name.Substring(1), stateVariable); }); } } catch (COMException e) { // this comes back for a reasonable percentage of the variables const int UPNP_E_DEVICE_ERROR = unchecked ((int)0x80040214); if (e.ErrorCode == UPNP_E_DEVICE_ERROR) { return; } // a few others fail here but they get updated by the service callbacks later... const int UPNP_E_INVALID_VARIABLE = unchecked ((int)0x80040213); if (e.ErrorCode == UPNP_E_INVALID_VARIABLE) { return; } // dunno about this one const int UPNP_E_VARIABLE_VALUE_UNKNOWN = unchecked ((int)0x80040212); if (e.ErrorCode == UPNP_E_VARIABLE_VALUE_UNKNOWN) { return; } Console.WriteLine("StateVariable Exception @ {0}: {1}", fi.Name, e.ToString()); } }