Endless error loop claiming device disconnected...

May 16, 2013 at 7:53 AM
I have a problem whereby when the system errors it will not stop until I re-start my software...

I do initialize my RemoteDeviceManager in my form's Load event handler. However, when it errors, I re-initialize it.

It doesn't fail when it gets to the
                //Find first connected device
                RemoteDevice objDevice = m_objDM.Devices.FirstConnectedDevice;
But it does fail when it gets to
                //Find what folder a storage card would use if it were installed
                RemoteDevice.DeviceRegistryKey objSDMemoryKey = objDevice.DeviceRegistryLocalMachine.OpenSubKey("System\\StorageManager\\Profiles\\SDMemory");
Here's my catch statement
            catch (System.Exception ex)
            {
                MessageBox.Show("Error connecting to the device. Please try again.");
                m_objDM = new RemoteDeviceManager();
            }
And this is the message that is contained within ex
This operation cannot be completed on a disconnected device.
The exception is a
InvalidOperationException
Disconnecting and re-connecting the device does not fix this issue.

Any and all help would be greatly appreciated!

Thanks!
Jarvis
May 16, 2013 at 8:10 AM
Upon further looking through the discussion forums it looks as though I may need to handle the DeviceConnected and DeviceDisconnected events and "get" my objDevice from there. Which would mean I would need to make the "device" a global object. I generally wouldn't care much about the connected device unless I'm attempting one of the device operations which is why I have the code "contained" within the function.

I will try the events as that may be more useful to not getting this error that will never fix without closing my application which makes it look as though my application has the issue.

Thanks!
Jarvis
May 17, 2013 at 7:22 AM
So I noticed that I wasn't re-building the full RemoteDeviceManager() object (m_objDM). Here is now my catch exception. This seems to be working more smoothly and I have not been able to force the error. This update (2.0) made it hard to force the error in the first place, but I did figure out how to do it...

When the device was attempting to connect, I would continuously press my button that started this process and it would end up in the endless error state. (Endless until I restarted the app). So I dug around and figured out what else I needed that happened during the "restart" of the application that maybe I could put into the catch statement.
            catch (System.Exception ex)
            {
                MessageBox.Show("Error connecting to the device. Please try again.");
                m_objDM.DeviceConnected -= m_objDM_DeviceConnected;
                m_objDM.DeviceDisconnected -= m_objDM_DeviceDisconnected;
                m_objDM = new RemoteDeviceManager();
                m_objDM.DeviceConnected += new EventHandler<RemoteDeviceConnectEventArgs>(m_objDM_DeviceConnected);
                m_objDM.DeviceDisconnected += new EventHandler<RemoteDeviceConnectEventArgs>(m_objDM_DeviceDisconnected);
            }
I hope this helps someone else.

I do not get my "Device" object from my Device Connected/Disconnected events. I use those to trigger when I want to do something else.

Thanks for this great library that has saved me a ton of time!! I hope to continue using it more extensively in the near future.

Jarvis
Sep 12, 2013 at 8:33 PM
dahal,

I'm still having this issue every so often. I've slimmed down the number of times it happens, but I'm still running into an issue where it's unable to recover the RAPI connection even though I can still interact with the device through the Windows Mobile Device Center and/or ActiveSync 4.5.

Any ideas?

Thanks!
Jarvis
Dec 9, 2013 at 8:46 AM
Hi All,

I am also struggling with the same problem. Device is connected and the device list has the device. But when i try to access device storage, i am getting an exception.

When i restart my program, program can access device storage.
Please give a tip to re-initialize the RAPI?

Thanks.
Orcun.