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

Visual Studio and MSTest: Deploying Files

Table of contents for Visual Studio and MSTest

  1. Visual Studio and MSTest: Introduction
  2. Visual Studio and MSTest: Deploying Files


Microsoft’s unit testing infrastructure provides a number of options for deploying files to the test directory when running tests.

  • Deploy files/directories for all tests in all test projects.
  • Deploy files/directories for a specific test, specified in the UI.
  • Deploy files/directories for all tests in a test class, specified in code.
  • Deploy files/directories for a specific test, specified in code.

All tests in all test projects

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.

Specific test in UI

You can specify files and directories to deploy on a test-by-test basis as well, stored in the test run configuration file.

  1. Select a test in the Test View window or in the Test List Editor.
  2. Press F4 to view the properties of the test.
  3. Click the Deployment Items property. An ellipses (…) appears in the value column.
  4. Click the ellipses. The String Collection Editor dialog box is displayed.
  5. Specify files and folders to deploy, one per line.

You’ll note that by adding deployment items in this way, Visual Studio will actually add DeploymentItem attributes to your code for the test.

Test class or specific test in code

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()
    {
        ...
    }
...
}

Notes

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.

Resources

Leave a Comment

Visual Studio and MSTest: Introduction

Table of contents for Visual Studio and MSTest

  1. Visual Studio and MSTest: Introduction
  2. Visual Studio and MSTest: Deploying Files


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:

  1. You can be sure that each test run is working with the latest files that have been built. There won’t be any extra cruft available from a previous test run.
  2. Code coverage data is collected only when tests are deployed in this manner.
  3. Some tests won’t be run unless they are deployed to a separate folder, specifically smart device tests.

Of course, there are some gotchas as well with deploying to a separate directory:

  1. You have to copy external files in multiple places (one for manually debugging, one for test deployment).
  2. The mechanisms for copying files to a test deployment aren’t completely analogous to those for copying them for manual debugging. For example, there doesn’t appear to be any way to specify that you want to copy files from a matching configuration (e.g. Debug or Release).

To change how tests are run:

  1. Bring up the test configuration properties by clicking on Test -> Edit Test Run Configurations -> Local Test Run (or whatever your test run configuration is called).
  2. Select the Deployment item in the list on the left.
  3. Check the Enable deployment checkbox to enable deploying tests to a separate directory for each test run. Uncheck the checkbox to run tests out of the build target directory.

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.

Resources

Leave a Comment

.NET Framework Setup Verification Tool

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!

Resources

Leave a Comment

Edit file in Visual Studio from command line

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!

Leave a Comment

Precedence of id and class in CSS

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>

Leave a Comment

Multiple Perforce Servers

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.

Installing Multiple Perforce Services on Windows

The procedure is documented on Perforce’s website, but I’ve reproduced the steps here for simplicity.

  1. Create a new directory for the Perforce service.
  2. Copy the server executable, service executable, and license file into this directory.
  3. Create the new Perforce service using the svcinst.exe utility.
  4. Set up the environment variables.
  5. Start the new service.

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

Notes

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.

Wish List

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.

Leave a Comment

Enable Ping on Windows Server 2008

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.

Windows Firewall Control Panel

Display the Windows Firewall control panel and click the Advanced settings link on the left.

1-Enable Ping-Windows Firewall

Inbound Rules

Click on the Inbound Rules entry below the Windows Firewall with Advanced Settings entry in the left pane.

2-Enable Ping-Inbound Rules

Echo Request Rules

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.

3-Enable Ping-Echo Request Rules

Enable the Rules

Right click on a rule and click on Enable.

4-Enable Ping-Enable Rule

Once the rule has been enabled, the icon will turn green and the value in the Enabled column will change from No to Yes.

5-Enable Ping-Rule Enabled

Command Line Control

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.

Resources

Comments (7)

osCommerce admin login won’t login

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.

  1. Edit catalog/admin/includes/application_top.php
  2. Comment out the block of code below the comment that says:
    // redirect to login page if administrator is not yet logged in
  3. Log in to the admin panel
  4. Click on the Administrators link.
  5. Edit the administrator in question.
  6. Change the password.
  7. Uncomment out the block of code previously commented out.

Thank you Dan O’Brien!

Resources

Comments (3)

mysql_connect to localhost on Windows 7 and Windows Vista times out

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:

  1. Edit the %SystemDrive%\System32\drivers\etc\hosts file.
  2. Make sure the following line is not present or is commented out:
    ::1         localhost
  3. Make sure the following line is present and is not commented out:
    127.0.0.1   localhost

Doing this solved the problem completely for me.

Update 12/29/2009

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.

Resources

Comments (8)

Page 1 of 161234510...Last »