Multiple operating system support

Nov 7, 2009 at 7:51 PM
Edited Nov 7, 2009 at 7:51 PM

Hi,

I would like to say thanks for the great library. I've spent a couple of days just to do a few basic RAS functions without DotRAS library. Now with it I've managed to enumerate, connect/disconnect & watch the RAS connections which is awesome.

My problem is that I've written my application (project home page: http://code.google.com/p/traffic-splitter/) in C# Express 2008 on Windows XP, so I've used the XP DotRas.dll, which doesn't seem to be working on Windows Vista or 7 for some reason. The features that are working on XP is more than enough for me. I just want my app to work exactly the same in newer operating systems.

Now my question is, how should I approach the coding/setup package of the project so that it would work on both XP and newer operating such as Vista/7? Must I recompile my whole project in Windows 7? I'm actually busy installing Windows 7 on a Virtual Machine just for this purpose :(

Help/suggestions would be appreciated.

Regards

Chris

Coordinator
Nov 8, 2009 at 2:40 AM

You probably need to elevate the privileges of your application since you're accessing protected areas of the operating system. Have you tried running your application as administrator? Also, what exactly isn't working? I need a more specific example if you want me to narrow down what the problem(s) might be. If you're catching a RasException, I'll need the ErrorCode.

Nov 8, 2009 at 12:49 PM
Edited Nov 8, 2009 at 1:17 PM

Thank you very much jeff_winn.

I haven't included much try catch statements, so my application simply didn't start up on Windows 7. It immediately said that the application stopped responding.
I've now installed Windows 7 x64 in a VM to test it myself. I've then gone and added Try Catch statements and compiled it in XP again.

This time my app gave the following error (and no, its not a RasException):

 

Error: 'deviceType' cannot be a null reference or empty string.
Parameter name: deviceType

StackTrace:    at DotRas.ThrowHelper.ThrowArgumentException(String argumentName, String resource, Object[] args)
   at DotRas.RasDevice.Create(String name, String deviceType)
   at DotRas.RasHelper.GetEntryProperties(RasPhoneBook phoneBook, String entryName)
   at DotRas.RasEntryCollection.Load()
   at DotRas.RasPhoneBook.Open(Boolean openUserPhoneBook)
   at TrafficSplitter.AdapterFunctionsRAS.EnumerateInterfaces(List`1 adapters) in C:\Documents and Settings\Chris\My Documents\Downloads\TrafficSplitter2\TrafficSplitter2\AdapterFunctionsRAS.cs:line 77

 

 

Where line 77 is the foreach line:

 

RasPhoneBook pb = new RasPhoneBook();
pb.Open(false);
foreach (RasEntry entry in pb.Entries)
{
     adapterNames.Add( entry.Name);
}

 

 

I've tried to run the exact same code in Windows 7, but I got that same error. I then changed the pb.Open(false) line to pb.Open(true); and it then worked without the error. When I've replaced the reference with the Win2K8 dll, the pb.Open(false); is working again, but then it won't work in Windows XP

Help would be appreciated.

Regards
Chris

Coordinator
Nov 8, 2009 at 1:17 PM

It sounds to me you may have corrupted the all users phone book file while playing with the project. What's happening is the entry you're trying to load has no device associated with it, which should never happen. Were you manually creating entries at some point? There are some static methods on RasEntry designed to assist people with creating a couple standard entry types. I did this because of the amount of data on each entry, users were having troubles creating entries that would work correctly.

The file will be sitting at the location returned to you by RasPhoneBook.GetPhoneBookPath(PhoneBookType.AllUsers) method which does change on each operating system.

Nov 8, 2009 at 1:22 PM
Edited Nov 8, 2009 at 1:23 PM

Hey jeff_win, its not that they have a corrupted All Users Phone book. Its simply that they don't have one yet.

I've told my clients/beta testers that they should simply create a PPPoE/VPN connection for All Users and then delete it.

Would it be possible in the next release to put in a check if the phone book exists, to prevent it from crashing/throwing that error?

Coordinator
Nov 8, 2009 at 1:30 PM
Edited Nov 8, 2009 at 1:31 PM

They don't have what, a phone book or a device?

By the way, you can simply call me Jeff. Everyone else around here does. :)

Nov 8, 2009 at 1:41 PM
Edited Nov 8, 2009 at 1:57 PM

Jeff, they simple didn't create a device for all users yet, meaning that the all users phone book doesn't exist.

I thought of using only the current user's phone book, but my Windows XP doesn't have a phone book for the current users though. Otherwise I should maybe try to open the all users' phone book, and if that fails I should open the current user's phone book.

Coordinator
Nov 8, 2009 at 1:50 PM
Edited Nov 8, 2009 at 2:01 PM

If they didn't have a phone book yet, it wouldn't be trying to load an entry from the phone book...

When it hits the line "at DotRas.RasHelper.GetEntryProperties(RasPhoneBook phoneBook, String entryName)" in your stack trace, it's telling me that the RasEnumEntries API call has found you do have an entry in the phone book, which it's trying to load and that particular entry does not have a device associated with it. If the phone book wasn't available, it would never hit that line, and the collection would simply be an empty collection once the Load method from your stack trace was completed.

Edit: We may have some confusion here about what constitutes a "device" and what constitutes an "entry" in this project. A device is a piece of hardware upon which a connection is negotiated. An entry is a connection listed in the phone book which uses the hardware device and contains information about the connection that will be used during negotiation. RasDevice is the implementation of a device, and RasEntry is the implementation of an entry in this project. Normally "creating" a device would mean you've added a piece of hardware to the machine, which is why I have warnings on that RasDevice.Create method that's exposed. Devices aren't specific to a phone book, they're specific to a particular machine since one machine might have hardware another machine does not.

Nov 8, 2009 at 3:23 PM

Sorry about that confusion with the Device & Entries. I actually know quite a bit about networking too, although my terminology/descriptions aren't always accurate/correct.

Well, I don't know what else it could be. Like I said: I got that error on a clean Windows 7 installation. I've created a VPN entry for my current user, and I still got that "deviceType = null' error. As soon as I've created another VPN entry, this time for all users, and then removed it again the "deviceType = null" was fixed. So my guess still remains that the phone book wasn't created yet.

When I go and delete the all users' rasphone.pbk file & folder afterwards, I get a different error though:

Error: The directory name C:\ProgramData\Microsoft\Network\Connections\Pbk is invalid.

StackTrace:    at System.IO.FileSystemWatcher.set_Path(String value)
   at DotRas.RasPhoneBook.Open(String phoneBookPath)
   at DotRas.RasPhoneBook.Open(Boolean openUserPhoneBook)
   at TrafficSplitter.AdapterFunctionsRAS.EnumerateInterfaces(List`1 adapters) in C:\Users\Chris\Downloads\TrafficSplitterBeta4Src\TrafficSplitter2\AdapterFunctionsRAS.cs:line 45


My solution

I've now simply modified my application to try both the current and all users' phone books, which seems to be the better choice than simply showing the either the entries from one of the phone books.

Coordinator
Nov 8, 2009 at 5:28 PM

"Sorry about that confusion with the Device & Entries. I actually know quite a bit about networking too, although my terminology/descriptions aren't always accurate/correct."

I'm sure we all have problems with terminology once in a while, no biggie.

"When I go and delete the all users' rasphone.pbk file & folder afterwards, I get a different error though:"

Yeah, that's a known issue with the release (that's noted on the download page for it, along with the fix) which will be taken care of in 1.2.

"I've now simply modified my application to try both the current and all users' phone books, which seems to be the better choice than simply showing the either the entries..."

That's how Windows operates, which causes more problems than it helps for people interacting with this assembly. They expect to open the phone book and occasionally the entries they expect to see aren't there because they're in the other phone book.


Would you be opposed to downloading the source and stepping through it when it's loading the phone book? I don't have trace enabled in the assembly yet (that's another 1.2 feature), so the only way to really see what's going on in there is to debug it from the project. I'm curious what exactly it's trying to load over there that it thinks is in the phone book. Regardless I'm going to add a work item to verify when loading entries to make sure the device is valid before attempting to create it. That should at least stop the exception you're seeing.

Thanks for bringing this to my attention!