Visual Studio vs mIRC

I’m doing some ASP.NET development in Visual Studio 2005 at the moment, and I’ve spent the last half hour beating my head against the wall because of an obscure error message:

ASP.NET Development Server failed to start listening on port 1651.
Error message:
Only one usage of each socket address (protocol/network address/port) is normally permitted.

This happened whenever I tried to run the application, or use the ASP.NET Configuration utility. (The idea is that Visual Studio has its own webserver built in, so you don’t need to have IIS or equivalent installed on your development machine.)

I went to a command prompt and ran “netstat -a” to see whether anything else was using that port. Port 1651 wasn’t listed there, although 1652-1654 were. I ran the command again as “netstat -a -b | more” to find out ownership info, and it turned out that mIRC was using those nearby ports. So, I closed mIRC down, and was able to run the ASP.NET apps without any trouble.

Curiously, I then restarted mIRC, and I can still run the ASP.NET apps. Running netstat again, I see that “WebDev.WebServer.EXE” is using port 1651 and “mirc.exe” is using port 2064. So, there’s probably a random element to port assignment.

Hopefully this info will be useful to other people: even if you aren’t using the same applications as me, the basic principle should still be valid (e.g. if Apache is conflicting with iTunes).

Upgrading to Visual Studio 2005

Today I got my copy of Visual Studio 2005 through the post, so I’ve been having a play with that, by upgrading some of my VB.NET 2003 projects. Unfortunately, I got a rather confusing error message from them, and I couldn’t find much info on the web, so I’m documenting it here for other people’s benefit.

The error is something like this:
‘FMain’ is a type in ‘Presentation’ and cannot be used as an expression.
where FMain is the name of my startup form and Presentation is the name of the project. However, there’s no line number given, and I can’t find any code that refers to the form.

If I then go to Project Properties, and check the box for “Enable application framework”, that displays an error message that says “Startup object must be a form when ‘Enable application framework’ is checked.” In my case, the startup object is a form (i.e. it inherits from System.Windows.Form), but if I find a different form that the framework checkbox will accept then that also fixes the compilation error.

You can create a new form, set that as the startup object, then enable the application framework, and this is pretty much guaranteed to work. Once you’ve done that, the “startup object” dropdown list is renamed to “startup form”, and it is filtered to what VB considers to be a valid list.

It turns out that the “Sub New” method in the startup form has to be Public (rather than Friend). That’s the default for new forms, but I’ve been changing that for all of mine in the past, to improve security (“don’t expose any more info than you need to”). Similarly, this Public constructor can’t take any parameters.