This project is read-only.

RasDialer.Dial() throws exception; how to get status in advance or prevent?

Jan 9, 2015 at 3:43 PM
at first thank you for the great project DotRas. In general it is working very successful in my environment.
I am using it to establish a RAS connection via a serial connection via USB using SLIP. (Do not ask why, but the hardware platform attached needed this technique.)

When no problem occurs everything is fine.
I am preparing the connection roughly as follows:
dialup= RasEntry.CreateDialUpEntry("Name", "0", GetRasDeviceByName(slipConnection.LinkedModemName, RasDeviceType.Modem));
                    dialup.EntryType = RasEntryType.Internet;
                    dialup.FramingProtocol = RasFramingProtocol.Ppp;
                    dialup.DialMode = RasDialMode.None;
                    dialup.IPAddress = IPAddress.Parse("");
                    dialup.NetworkProtocols.IP = true;
                    dialup.Options.UseCountryAndAreaCodes = false;
                    dialup.Options.DisableNbtOverIP = true;
                    dialup.EncryptionType = RasEncryptionType.None;
                    dialup.PhoneNumber = "";
                    dialup.Options.DisableLcpExtensions = true;
                    dialup.Options.DoNotNegotiateMultilink = true;
slipDialer.EntryName = "Name";
slipDialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers);
RasHandle = slipDialer.Dial();

The big problem here is that I do have some cases where Dial() fails with an exception. This is the case when a previous connection attempt somehow was not succesfully established or was canceled somehow. In Network overview I can see 'Connection is being established' forever.
(unfortunately german...)

I wonder if there is any possibility to cancel the connection attempt?
The only solution I currently have is to restart windows.

Regards in advance,
Jan 15, 2015 at 4:50 AM
If you're calling Dial and not DialAsync on RasDialer, Windows shouldn't be releasing it until the connection is completed or terminated. If it isn't, there won't be much we can do to fix that, as the RasEnumConnections API doesn't return connections that aren't completely connected.

Might want to try switching to DialAsync so you can call the Cancel method if you need to so you can terminate the connection in progress by the component. Aside from that it could just be a problem with the driver (which is highly likely).
Jan 15, 2015 at 11:06 AM
Edited Jan 15, 2015 at 11:28 AM
thanks for your reply jeff_winn.

I already did some tests using DialAsync. But the problem persists.
As you mentioned it seems not to be possible to get a handle to the connection that is still connecting. My problem is I loose the handle on improper application exit, thus I do not currently see a way to get the handle to even fire a DialAsyncCancel().

does not return a RasConnection so object so I suppose it already starts there.

I still wonder that there is no workaround instead of restarting whole Windows. Maybe there is a timeout for dialing a connection to be set?

I suppose I found an explanation in SDK that states that dotras can do nothing against the problem:
"Failure to dispose of this component may result in a connection attempt hanging, which will require the machine to be restarted before the connection is released."
So it seems there is nothing possible except reboot?
Really unbelievable...

Jan 16, 2015 at 4:02 AM
I've got pretty much the entire RAS API wrapped, adding my own timeout won't do anything but make matters worse, it won't change the fact that Windows doesn't have a timeout available.

The problem you're seeing is your application is corrupting what I refer to as the RAS state machine. Windows cannot shut off by someone just clicking the X on a window. So, when the callbacks it wants to have in place are not available because your application is no longer in memory, it doesn't know what to do. Disposal of the component ensures that the callbacks are removed and any connection attempt that is pending is terminated. However this usually happens with people using DialAsync more than Dial since there are no callbacks used by Dial, which that could end up meaning there's a potential driver issue.

Windows 8 handles it a bit better and doesn't always require a reboot to fix it, but unfortunately that's just how RAS works. All I can do is put a wrapper around the API, I can't change how Windows operates (though they did fix a bug I submitted after a year or two).
Jan 19, 2015 at 6:29 PM
I'd like to echo what jeff_winn has said about the driver - in my experience, particularly with cellular modems, there are many "wonky" behaviours that seem to reflect massively un(der)documented features in Windows. I too at one point tried to allow cancellation of dialing and it proved very tricky - we eventually gave up on it, IIRC.