View Single Post
  #5 (permalink)  
Old November 30th, 2010, 03:30 PM
jlakes jlakes is offline
Registered User
Join Date: Aug 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Success at last! Microsoft pointed me in right direction!

After attempting without success to convert our existing, moderately complex Web forms application to an ennvironment that includes MVC2, I opened a trouble ticket with Microsoft in hopes that they could help me resolve the issue. The engineer who helped me was very aware of the instructions in Chapter 12 of "Professional ASP.NET MVC2." We walked through this together and he agreed that I had done everything correct. He took a day to study our code and concluded that the application must be converted from a Web Site Project (WSP) to a Web Application Project (WAP). In his own words, "MVC2 does not play well with WSP-based applications." Instead of starting out with my big project, I took a smaller WSP project and followed the instructions found on for "Converting a Web Site Project to a Web Application Project." The instructions were very clear and straight-forward. I easily converted my simple app to WAP and then added in the MVC2 framework with no problems. It turns out that all of my projects I have worked on since Visual Studio 2005 have been WSP projects. I had not paid much attention to the difference between WAP and WSP. Since my projects had all been working quite well, I was happy to leave well enough alone. So I had to educate myself on the differences of WSP and WAP. There are many interesting blogs posted about this, including this one by Vishal Joshi:

I'm in the process of converting all my project to WAP for many of the reasons spelled out in Joshi's blog.

Next I returned to Chapter 12 and repeated the steps outlined and sure enough everything worked fine! Now I needed to convert my larger more complex application. This was not as straight forward as I had hoped.

After experimenting with this for a few days and discovering that I would need to perform a lot of steps I decided that I should break the project down into 8 mostly distinct steps. Each step included several tasks. To keep track of all this I used Visual Source Safe to keep acurate track of what I had completed and allow me to easily roll back to any of the steps. OK, so after performing the following steps, I succesfully created a WSP to WAP application that included MVC2 framework. It worked! Here are my steps, which reflect all of the issues I ran into (you may not run into these, or you may run into others). I was using Visual Studio 2010 Ultimate:

1. Create a new WSP project from my current project and bind to VSS. (Essentially, I branched my current WSP project for safety and to keep track of my steps).
2. During my experimentation I found that a previous programmer on the project had named one of the user controls the same name as one of the global classes. This is not a problem with WSP but conflicts in WAP. So, while still a WSP, I renamed the user control from "Product" to "ProductUC" so that it would not clash with the "Product Class". I then had to change all the code that referenced this user control with the wrong name. Again, checked this in to VSS to keep track of my steps.
3. Create a new empty WAP project within a new solution. Add the WSP project to the new solutions. So I have a solution (ITSol) an empy WAP project within the solutions (ITWap) and the WSP project to convert within the solution also (ITWsp).
4. My solution (ITSol) now contains two projects: ITWap and ITWsp. First I deleted the ITwap web.config file that had been created automatically. Next I added in all the assembly references from the ITWsp project (Right-click on the ITWap project icon and choose "Add Reference." From the "Add Reference" dialog, select "Browse" tab. Find the bin directory from the ITWsp project and select all the file.dll and click OK. This should add all your references to the ITWap project. Now copy all the code contained in the App_Code folder from the ITWsp to the ITWap. Right click on the ITWap App_Code directory and select "Convert to Web Application." You will notice that Visual Studio renamed your App_Code folder to Old_App_Code. If you don't understand why it did this, stop and do some research on how WAP projects are different from WSP projects before proceeding. After this step, I tracked my changes in VSS.
5. Copy all the application files from ITWsp to ITWap. I did not copy the Global.asax file over because I wanted to generate a new one using the "add new item --> global.asax file" within visual studio 2010. I then studied my WSP global.asax file and copy/pasted the content. (You may not need to do this, but our code had a lot going on in this file). Next, from the ITWap root node, choose "convert to web application."
6. Now attempt to build the application. In my case the new ITWap had many errors relating to our use of the "ProfileCommon" Class which we used in conjunction with the membership system. With a little research I learned that this would require some changes. The best information I found on this was a blog posted by Jon Galloway, "Writing a custom ASP.NET Profile class":

I carefully followed his instructions and successfully implemented a new UserProfile class based upon the ProfileBase.
7. Address build issues that a now exposed. OK, I'm no longer getting any "PofileCommon" build issues. Still, though, there are some minor build issues showing up. In my case, this included some objects of different types that had the same name. I had to go through the code and change these. For instance a view object named "LineItemsView" conflicted with a variable named "LINEITEMSVIEW." Also, during this process some of the Enterprise Library blocks we are using did not move over correctly and I needed to re-install these. Your issues, if any, may be different, but this is the point to tackle them. This is of course obvious, but I always find that very carefully reading the build error messages can lead to the solution. I have so often read only the first part of the message and attempted to fix it only to go back later and realize it actually contained more useful information in the detail. I also ran into some Theme issues, one of which I still haven't figured out. The ITWsp used menutabs in several places and the CSS applied to these is not gettinig picked up. But, the ITWap builds and generally runs correctly! Again VSS checkin.
8. Finally then: Install MVC2 framework to the ITWap and validate that both frameworks (Web Forms and MVC2) work correctly. For the first time ever, this worked correctly with my moderately complex web forms application!

I spent 2 solid weeks getting my WSP application converted to a WAP application that could incorporate the MVC2 framework. If you are having similar issues, I hope this posting will help you.

Last edited by jlakes; November 30th, 2010 at 04:19 PM..