Wednesday, 24 September 2008

Fix for ASP.NET MVC Preview 5 bug with Visual Studio 2008

We've had some trouble using the latest ASP.NET MVC Preview 5. For reasons unknown any attempt to open a view (e.g. Default.aspx, not the code-behind) in Visual Studio 2008 would cause a fatal .NET runtime error and the Visual Studio process would simply be killed. Dead. Gone.



Annoying.

I spent a good amount of time trying to figure out why this could be, and though there were a few leads on the web none of the proposed solutions out there fixed the problem. So, I asked the senior developer on my team, Steve Friend, to have a look. Sic' em, Steve!

Steve noticed that Scott Guthrie's Preview 5 Example Application wouldn't cause any problems at all. Nor would any MVC project added to the same solution as Guthrie's application. However, all other MVC projects created from scratch with Visual Studio would suffer from the symptom described at the top of this post.

Steve examined the differences between ScottGu's application and a 'fresh' MVC app, and discovered that removing two of the DLLs from the fresh MVC app's /bin folder solved the problem. He documented this on our internal wiki, and I've copied-and-pasted his fix here. Thanks Steve!


-------------
Creating a new project
In Visual Studio create a new MVC project (File > New > Project, then select Visual C# > Web then select ASP.Net MVC Web Application). This will create a fairly large default project containing a number of folders and files relating to the MVC pattern structure (i.e. models, views and controllers).

Once you have done this you will need to build the project and create a new website in IIS (see IISSetup for details of how to do this), but before you do that, run through the instructions below to avoid the bug that seems to ship with default projects.

The bug
If you double click on any view page (i.e. a aspx page) in order to edit it in Visual Studio the application crashes.

The fix
In the solution explorer select "Show all files" to reveal the bin folder. In there you will the following dlls (and possibly more, if you have already built your project/solution):

* Microsoft.Web.Mvc.dll
* System.Web.Abstractions.dll
* System.Web.Mvc.dll
* System.Web.Routing.dll

Delete "System.Web.Abstractions.dll" and "System.Web.Routing.dll".

5 comments:

panjkov said...

I had same problems and posted my workaround on forums.asp.net. In my case, that workaround wasn't enough.

Anonymous said...

Thanks!!!!!

Øyvind Valland said...

Hello guys,

I'm glad that this is of help. The real thanks goes to Steve F, though - for finding this fix. I'm just a messenger. Now if only Steve would set himself up with a blog...

Anyway, it does appear that this fix isn't universal, meaning that it doesn't work for everyone. I can only say that if you find another fix, please post it on forums.asp.net, and put a comment here with a link as well so that people can find it.

Hopefully ASP.NET MVC will be in BETA soon, and then I'm sure these problems will be gone!

Krishna.K said...

thanks! Great help!

Anonymous said...

thanks man, glad you've wrote about it. keep the good stuff coming ;)