Web application times out when debugging
This article has moved to my new technical blog site.
http://davidstechtips.com/2010/06/web-application-times-out-when-debugging/
Comments Off
This article has moved to my new technical blog site.
http://davidstechtips.com/2010/06/web-application-times-out-when-debugging/
Comments Off
Table of contents for Visual Studio and MSTest
Microsoft’s unit testing infrastructure provides a number of options for deploying files to the test directory when running tests.
The Deployment page of the test run configuration dialog not only allows you to specify whether you want to deploy to a separate test directory for each test run. It also allows you to specify files and directories to deploy when a test is run. The configuration page allows you to specify individual files as well as directories. This configuration is stored in the .testrunconfig file.
You can specify files and directories to deploy on a test-by-test basis as well, stored in the test run configuration file.
You’ll note that by adding deployment items in this way, Visual Studio will actually add DeploymentItem attributes to your code for the test.
Microsoft provides the DeploymentItem attribute for specifying items to deploy in code. This is a good solution if you have tests that need different sets of files to be deployed. The documentation and quite a few blog posts say that this attribute only works on methods marked with the TestMethod attribute, but I found that it also works on classes marked with the TestClass attribute.
There are two flavors of this attribute. The first allows you to specify a source path for a file or directory. As specified above, you can specify an absolute or a relative path to the file or directory. Also as above, file paths are relative to the test project while directory paths are relative to the solution.
The second flavor also allows you to specify a destination directory. The destination directory is relative to the test directory.
Example:
// Deploy all files in the OtherProject\dll directory to the test directory.
[TestClass]
[DeploymentItem(@"OtherProject\dll\")]
public class MyProjectTest
{
...
[TestMethod]
// Deploy test.xsl to the xsl subdirectory below the test directory.
[DeploymentItem(@"..\OtherProject\test.xsl", "xsl")]
public void Test1()
{
...
}
...
}
You can specify absolute or relative paths. Microsoft’s MSDN article on this subject says that relative paths are relative to the RelativePathRoot setting found in the .testrunconfig file. However, what if that setting isn’t set? It turns out to be different for files and for directories. For files it is relative to the test project. For directories it is relative to the solution. Sure would be nice if they would be consistent.
To specify a directory, end the line with a backslash.
When deploying a directory, it doesn’t preserve the source directory structure. It simply copies all files from all directories and subdirectories into the test directory.
You can use environment variables in paths. However, you can’t use Visual Studio macros such as $(ConfigurationName) in paths. This is unfortunate as that leaves no way to deploy configuration-specific files to the test directory.
Ade Miller wrote a good article on some of the gotchas of using the DeploymentItem attribute. The article is a good read and addresses handling deployment failures, duplicate file names, and how to handle tests that change deployed files.
Table of contents for Visual Studio and MSTest
I’m coming up to speed on my new company’s development environment, and part of that is the usage of Microsoft’s unit testing infrastructure built into Visual Studio 2008. One of the things the tests need to be able to do is load DLLs provided by a third party. However, the unit testing environment is (or rather, can be) different that the manual debugging environment. To set up for manual debugging, typically you add a post-build command to copy the files to the target directory, which is identified as $(TargetDir). The unit testing infrastructure, however, copies everything it thinks is needed to a new folder below the TestResults directory for each test run. You can, of course, choose to disable this behavior and just run your tests from the target directory like you do when you manually debug the project. However, there are a number of benefits to deploying them to a separate folder:
Of course, there are some gotchas as well with deploying to a separate directory:
To change how tests are run:
The configuration dialog box also allows you to specify files to deploy to the test directory when a test is run. File deployment is a topic that deserves its own article, however.
I was running down an issue with building a 32-bit application in Visual Studio 2008 on a 64-bit version of Windows 7 and a number of articles online suggested that .NET Framework v2.0 should be reinstalled. Most of these were talking about Windows Vista, but I thought I would run this down. Aaron Stebner has provided a terrific tool to verify the installation of all versions of the .NET Framework that are installed on your machine called the .NET Framework Setup Verification Tool.
You can get the tool from Aaron’s SkyDrive. However, you will most likely also need to read Aaron’s .NET Framework Setup Verification Tool User’s Guide.
Pretty nice tool!
For years I’ve used a tool I found internally at Microsoft called VSEdit to load a file into an existing instance of Visual Studio from the command line. Microsoft released that handy little tool on MSDN (albeit without the source), but they also added the feature directly to the Visual Studio executable image (devenv). Sara Ford from Microsoft blogged about it on her MSDN blog.
All you have to do is launch the following command:
devenv /edit <filename>
That works great from a Visual Studio command line, which adds the correct directory to your path. After looking at all the executable images in that directory, I decided to add it to my path for all command prompt windows. For Visual Studio 2008, add one of these paths to your PATH environment variable (depending on if you are running on 32-bit or 64-bit Windows) and then relaunch your command prompt:
C:\Program Files \Microsoft Visual Studio 9.0\Common7\IDE C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE
Thanks Sara, and thanks Microsoft!
I’m working on converting a website template to a WordPress theme and discovered very interesting. Most people know that each browser interprets HTML and CSS differently, with Microsoft’s Internet Explorer (prior to IE8) appearing to be quite different than other browsers, such as Mozilla Firefox and Google Chrome. Today I discovered a specific difference in how IE interprets id and class differently than Firefox and Chrome. To IE 7, id and class appear to be treated equivalently, with neither having priority over the other. Firefox, Chrome, and IE8, however, give a higher precedence to id.
Here’s an example:
<style>
#selector1 { color: red; }
.selector2 { color: green; }
</style>
<div id=”selector1”>
<div class=”selector2”>
Some text
</div>
</div>
In the above example, the value specified for color on selector1 (red) will be used when displaying the page in Firefox, Chrome, or IE8. When displaying on IE7, however, the value specified for color on selector2 (green) is used. Therefore, the conclusion that can be drawn is that id selectors take precedence over class selectors.
Doing a little research, I found the W3C candidate documentation on selectors, which is what identifiers are called in a style sheet. The interesting chapters are Selectors (chapter 5) and Assigning property values, Cascading, and Inheritance (chapter 6), although even after reading those chapters it still wasn’t clear what the correct priority should be.
To get around this implicit priority, you can use the !important keyword:
<style>
#selector1 { color: red; }
.selector2 { color: green !important; }
</style>
I’m experimenting with multiple Perforce servers on Windows today, which is fairly simple to configure. I’ve run into a few gotchas, however, so I’d like to enumerate them here.
The procedure is documented on Perforce’s website, but I’ve reproduced the steps here for simplicity.
Here is an example set of commands for doing this from the command line:
rem Create the destination directory for the new server. rem This directory will contain the executable images and the depots. md C:\P4Root2 rem Copy the files to the new directory. copy "C:\Program Files\Perforce\Server\p4d.exe" C:\P4Root2 copy "C:\Program Files\Perforce\Server\p4s.exe" C:\P4Root2 copy "C:\Program Files\Perforce\Server\svcinst.exe" C:\P4Root2 copy "C:\Program Files\Perforce\Server\license" C:\P4Root2 cd /d C:\P4Root2 rem Create the service. svcinst create -n Perforce2 -e C:\P4Root2\p4s.exe –a rem Set the service parameters for the new service. p4 set -S Perforce2 P4ROOT=C:\P4Root2 p4 set -S Perforce2 P4PORT=1667 p4 set -S Perforce2 P4LOG=log p4 set -S Perforce2 P4JOURNAL=journal rem Start the service. svcinst start -n Perforce2
The example on the Perforce website uses a different name for the log and journal parameters (log2 and journal2). It’s not clear why this is necessary. I’ve had success with using the standard names.
The parameters for the new service are stored at HKLM \ SYSTEM \ CurrentControlSet \ services \ Perforce2 \ Parameters. However, changing them manually in regedit may produce unexpected results. I almost messed up my primary server by doing this.
If you need to change the port for a server, you must also stop and restart the service.
Don’t forget to add a rule to the firewall to allow connections to the Perforce Server in the new location. I spun for a little bit trying to figure out why I couldn’t connect from another machine to the new server.
My biggest wish is that there was an actual online community. Perforce references the online community on their support page, but there is no forum or bulletin board anywhere for asking questions. Rather frustrating if you ask me.
When setting up new servers, one of the first things to do is to make sure other machines can connect to. The easiest way to do that has typically been to use the ping command, which sends an Internet Control Message Protocol (ICMP) or Echo message to the remote machine. Due to security concerns, however, the Windows Firewall on Windows Server 2008 and Windows Server 2008 R2 is configured to disallow responses to these requests. Here is how to enable responses to these requests.
Display the Windows Firewall control panel and click the Advanced settings link on the left.
Click on the Inbound Rules entry below the Windows Firewall with Advanced Settings entry in the left pane.
There are two rules for echo requests, one called File and Printer Sharing (Echo Request – ICMPv4-In) and File and Printer Sharing (Echo Request – ICMPv6-In). You’ll find these in the contents pane on the right.
Right click on a rule and click on Enable.
Once the rule has been enabled, the icon will turn green and the value in the Enabled column will change from No to Yes.
Note that Windows Server Core does not have any UI. You can use the following commands from a command prompt window to enable and disable the IPv4 rule:
netsh firewall set icmpsetting 8
netsh firewall set icmpsetting 8 disable
Note that these commands have been deprecated and you’ll see this message when you execute them on Windows Server 2008 R2:
IMPORTANT: Command executed successfully.
However, "netsh firewall" is deprecated;
use "netsh advfirewall firewall" instead.
For more information on using "netsh advfirewall firewall" commands
instead of "netsh firewall", see KB article 947709
at http://go.microsoft.com/fwlink/?linkid=121488 .
I haven’t found the syntax for simply enabling and disabling the existing rules. All the examples I’ve seen have you create a new rule, like this:
netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol=icmpv4:8,any dir=in action=allow
If anyone can find the syntax for simply enabling and disabling the existing rules, please let me know.
I’ve been implementing a new website using the WP.osC framework (based on osCommerce) and ran into a problem of not being able to login to the admin panel. It would simply redirect back to the admin login page. This typically occurred when I would change the URL to the store website.
Quite a few people had the problem but one person (Dan O’Brien from Cornwall, England) provided the solution that worked for me.
catalog/admin/includes/application_top.php// redirect to login page if administrator is not yet logged inThank you Dan O’Brien!
I’ve been developing PHP websites against mysql on Windows Server 2003 and Windows Server 2008 R2 and finally decided I needed to start doing my testing and debugging on a client machine instead. My development machine runs Windows 7 so it is running the same version of IIS as my Windows Server 2008 R2 machine.
As I was getting everything setup, I installed phpMyAdmin and immediately ran into a problem. It would time out trying to connect to the database on localhost. Of course, I didn’t know that at the time as phpMyAdmin just displays a blank page. I found this article by Karina Myers that described a workaround – specify 127.0.0.1 for the host instead of local host. Specifically, change this:
$cfg[‘Servers’][$i][‘host’] = ‘localhost’;
to this:
$cfg[‘Servers’][$i][‘host’] = ‘127.0.0.1’;
Then I proceeded to install an osCommerce website and it had trouble as well. Fortunately I had Xdebug installed so I got some useful error messages. I should have guessed this before; the problem had to do with the mysql_connect() function trying to connect to localhost.
Fortunately for me, others have run into this before and the solution was posted to the documentation page for mysql_connect. Here is what you do:
%SystemDrive%\System32\drivers\etc\hosts file.::1 localhost127.0.0.1 localhostDoing this solved the problem completely for me.
I discovered tonight that this tip also fixes a problem I was having with the Beyond TV web admin on Windows Vista. When attempting to connect from the local machine by right-clicking on the Beyond TV tray icon and selecting Open Web Admin the browser would display an error page. After making the above changes to the hosts file, all was right with the world again.

David's Technical Musings © 2013 All rights reserved. .