Error Loading MVC 3 Project after MVC 4 is Installed or in VS 2011

Since installing the ASP.net MVC 4 Beta, it has happened to me a few times that MVC 3 websites will not load when the solution is loaded into VS 2010 (I have also read about this happening with VS 2011).

You can fix this by doing the following:

  1. In the Solution Explorer, right click on the project that wont load and click on “Edit [ProjectName].csproj”. This will open up the project definition file in VS. You can also edit this manually using your favorite text editor, opening the file through Windows Exporer.
  2. Find the line in the file that starts with ProjectTypeGuids and remove the entry “{E53F8FEA-EAE0-44A6-8774-FFD645390401}” from the list (this is code that tells Visual Studio that it is an MVC 3 project – for some reason, including this in the project file after installing MVC 4 messes things up).
  3. Save the .csproj. file and [Reload] the project through the Right Click menu in Solution Explorer.

The project should now load properly (if the MVC project has been the startup project for the solution, you may have to reset this as well).

I Love it When Technical Book Authors Have a Sense of Humor

I am going through Pro ASP.NET MVC 3 Framework by Adam Freeman and Steven Sanderson (@StevenSanderson) (Apress). Enjoying it so far – good technical writing, good level of detail mixed with useful examples of different implementation options.

And most importantly, they have a good sense of humor. From Page 381 (my highlights):

Quote from Pro ASP.NET MVC 3 (Sanderson & Freeman), page 381

If you don’t want to click on the link, they are talking about best practices for url schemas using MVC, and give an example of a link to Amazon as something not to do (I realize the irony of my linking to Amazon above). They then include in an aside:

Note To be very clear, we have only the highest respect for Amazon, who sells more of our books than everyone else combined. We know for a fact that each and every member of the Amazon team is a strikingly intelligent and beautiful person. Not one of them would be so petty as to stop selling our books over something so minor as criticism of their URL format. We love amazon. We adore Amazon. We just wish they would fix their URLs

.Another good one: The authors are talking about using MVC to create a REST API, where the same action name in a given controller can be overridden to handle HTTP Get/Post/Delete requests (page 476, my emphasis):

Now each StaffMember entity in our application can be uniquely addressed using a URL of the form Staff/123, and a client can use the GET, POST, and DELETE HTTP methods to perform operations on those addresses. This is called a RESTful API, except by people who claim to be experts in REST, who will tell you that nothing is truly RESTful except their own code. (We joke—sort of).

Gotta love it.

Crucible Code Review Wishlist

I have been trying out Crucible Code Review software from Atlassian (halfway through the trial) with a number of teams in my department. The competition in this area is pretty sparse, and each one has its other issues:

  • Kiln only works for Mercurial (which we may move to some day, but for now we are using SVN so we need a solution that works with that as also)
  • Review Board seems to be very popular, but just looking at the list of the dependencies gives me indigestion when considering an install on our Windows Server environment.
  • Code Collaborator is way too expensive without giving much extra (50 users in Crucible = $2200, 50 named users in Code Collaborator = $24,450)
  • Code Review Tool doesn’t have a very professional looking site, hardly any documentation and no plugin potential and no Mercurial support
  • Specatare‘s and Parasoft‘s websites are even sparser and gives almost no info (aside from a few screenshots) – not enough to make me spend the time trying it out.

On the other hand, thus far Crucible has delivered on the main functionality: establishing a medium for easily performing code reviews. The price is very fair and there is very decent documentation. We will probably go with it, just for those reasons alone.

That said, I have a number of issues with Crucible – posting them here in the hopes that someone from Atlassian will see this and can do something about some or all of them. Continue reading

Horrible Page Design at JPost.com

I just loaded up a link at jpost.com talking about how the Rami Levy supermarket chain predicts that by 2012 20% of food purchases in Israel will be online. However, when I loaded the link, it took me a minute to actually find the content. Can you see the problem here?

To make it a little bit clearer, I have added highlights – Ads are in yellow, In-site navigation is in green, and the content is in blue. The content occupies a tiny strip down the center of the page (maybe 30-40% of the total width of the page). This is surrounded on all sides several layers: Continue reading

Clearing out a Mysterious Table Lock (LCK_M_S) in Sql Server 2008

A user reported today that they were trying to query a table with 181 records and the output stopped at 178 and just hung there. I tried to replicate this and the same thing happened – also couldn’t run a Select (*) on the table. So I pulled up the Activity Monitor for the server and observed that there was only one query in process – the hung query. It listed the process as being suspended with a Wait Type of LCK_M_S. Some quick searching told me that the task was waiting to acquire a shared lock. However, it was not obvious what was locking the table. What to do?

After some more searching, I found two more posts that gave advice on what to do in the given scenario:

Based on these, I did the following:

    1. Ran Exec sp_who2 through Sql Management Studio. This gave me a list of all current processes. There was only one open process on this database at the time, so it was the likely culprit.
    2. Next, ran the code in the Sql Server Locks article above to show the process that was locking my table. Bingo – process 52.
USE DBNAME; GO;

DECLARE @dbid INT ; --what's the dbid for DBNAME?
SET @dbid = DB_ID() ;

DECLARE @objectid INT ; --what's objectid for our demo table?
SET @objectid = OBJECT_ID(N'TABLENAME') ;

--look at locking in the DB
SELECT  resource_type
       ,resource_database_id
       ,resource_associated_entity_id
       ,request_mode
       ,request_type
       ,request_session_id
FROM    sys.dm_tran_locks
WHERE   resource_database_id = @dbid ;

--limit the results to only the offending table
SELECT  *
FROM    sys.dm_tran_locks
WHERE   resource_database_id = @dbid AND
        resource_associated_entity_id = @objectid ;

After I had confirmed the identity of the process, I ran Kill 52 to kill the offending process. Everything immediately started working again with the table.

(After the fact, went back through the code with my team and found the spot where someone was running db.Connection.BeginTransation() on a data context that already had an open transaction, causing an error: “SqlConnection does not support parallel transactions“. And to make things worse, this was done outside of the try/catch/finally structure that ensured that any open transactions would be committed. Oy.)

As Pinal Dave writes:

As mentioned earlier, if you kill something important on your production server, there’s a great possibility that you’ll face some serious integrity issues, so I there’s no way I advise use this method. As the title goes, this is a dirty solution so you must utilize this only if you are confident.

It is important to keep that in mind. But that said, this technique for identifying and killing a hung transaction can definitely come in handy. (And be sure to backup your DB and transaction logs regularly!)

Web Surfing Helps at Work

I have been claiming this for years. Web Surfing Helps at Work, Study Says:

According to a new study, Web browsing can actually refresh tired workers and enhance their productivity, compared to other activities such as making personal calls, texts or emails, let alone working straight through with no rest at all….Because Web-surfing can aid productivity, the researchers caution employers against over-restricting workers’ Web access. They recommend that managers allow time for limited personal Web browsing “since it has a salubrious impact on employees’ productivity,” while limiting access to personal emails.

It has happened to me many times that I am stuck on a problem and just come up with a solution. Then I spend a few minutes “wasting time” on some website and the answer comes to me. Nice to see it substantiated in a study.