Visual Studio 2008 debugging and breakpoints

My development tools are currently Visual Studio 2008, Resharper 4.5, Gallio and Testdriven.NET. But for as long as I have used these tools, my Visual Studio debugger has only worked partly.

The problem

When I inserted some breakpoints in my code, the first one was almost all the time hit. However, when I tried to step through the code, it worked fine for a bout 3-6 steps. But then Visual Studio debugger decided that was enough, and just completed the code.

The good thing was, it forced me to write many unit test cases, but sometimes I really think it is nice to visually see the state of your objects, in the code.

I have spoken to colleagues, and tested with different combinations of Gallio, Testdriven.NET and Re-sharper enabled, as I thought they cased the problem. But the debugger just kept bugging me. I had actually given up finding a solution to this problem, thinking that Visual Studio 2010 would fix it.

The solution

So finally, in a complete other context, I stumbled upon this page:

http://code.msdn.microsoft.com/KB957912

And thought…. that title sounds interesting… I quickly moved to the KB article, and started to read. I thought, that sounds exactly as my problem.

With nothing to loose I installed the update, and started to test the debugger… until now it seems to work :)

- please note, I do not use the debugger that often as I write very reliable code :)

An Introduction to Native Concurrency in Visual Studio 2010

Visual Studio 2008 – ItemTemplatesCache missing

The issue 

My Visual Studio 2008 opened the solution file with no problem. However, when I was to add a new class, user control, aspx file or similar, I received the error:

Could not find part of "c:\Program Files\Microsoft Visual Studio 9.0\…\ItemTemplatesCache…"

[and the path to the ItemTemplatesCache in Visual Studio 2008 folder].

The solution

Well, one slution would be to reinstall or repair installation of Visual studio 2008. However, after searching for a while I found a solution that is much easier:

  1. Open "Visual Studio 2008 Command Prompt" as an Administrator
  2. Run the command: "devenv /installvstemplates"
  3. That's it

 

It takes a while but it completely rebuild your item template cache if it is corrupt or completely missing like me.

How Do I: Debug ASP.NET AJAX Applications Using Visual Studio 2005?

Original post here: http://www.asp.net/learn/ajax-videos/video-167.aspx

In this video we learn how to use Visual Studio 2005 to debug ASP.NET AJAX applications. We are shown how the ScriptManager is used to access the JavaScript created by the ASP.NET AJAX server controls, and we also see how to use the Sys.Debug class to insert a trace message and a breakpoint.

View video: WinVideo-ASP-DebugAJAXApplicationsUsingVisualStudio2005.wmv (16.89 mb)

Play Video

Using different Web.Config for development, test and production

Upgrading VS 2005 Web Site Projects to be VS 2005 Web Application Projects

Original post here: http://webproject.scottgu.com/csharp/migration2/migration2.aspx

Step 1: Create a New VS 2005 Web Application Project

The best strategy to migrate an existing VS 2005 Web Site Project is to first create a new blank VS 2005 Web Application Project in a separate directory. This avoids changing any of the existing web site files, and will allow us to copy in already implemented functionality. You can add this new project either to your existing solution (ideal when you have lots of other class library projects that you want to use), or by starting a new instance of Visual Studio and creating a new solution+project within it.

To create a new VS 2005 Web Application Project in a new solution, choose File->New Project and then select the ASP.NET Web Application Project option. If you want to add a VS 2005 Web Application Project to an existing solution right click on the solution node and select Add->New Project. Name the project whatever you want, and select the language type you want to use.

Once you’ve either created or added this new VS 2005 Web Application Project, delete the "default.aspx" and "web.config" that are added to it by default (since you’ll instead just want to copy in your existing ones). In this example I added the new Web Application Project to my existing solution. If you do this you’ll then be left with a blank project that looks like this:

 step1

Step 2: Setup Project References

Before migrating any code into your new VS 2005 Web Application Project, you should first make sure to setup any project or assembly references for it. You can see the list of default references with new VS 2005 Web Application Projects under the References node above. You can right-click on the References node to add new References to the project, as well as setup project-to-project references if you have other class library projects part of the solution.

Once you have all of your references setup for the project, right click on the project and choose "Build" (or just hit Ctrl-Shift-B). This will build the project and verify that any project to project references are working.

Step 3: Copy the files from the Web Site Project into the new Web Application Project

The easiest way to add your existing files from a VS 2005 Web Site Project is simply select all the files in the Web Site Project copy and paste them into the New Web Application Project.

At this point none of the files have been converted and the directory structure looks the same as it did in the Web Site Project.

step2a

If the Data Source Configuration Wizard is launched during the copy, cancel the dialog and allow the rest of the files to be copied.

step2aa

One difference between a VS 2005 Web Site Project and a VS 2005 Web Application Project is that the VS 2005 Web Site Project Model dynamically generates the tool-generated partial class half of a page, and does not persist it on disk. The VS 2005 Web Application Project model on the other-hand does save this partial class on disk within files that have a .designer.cs extension and compiles it using the in-memory VS compilers when a build occurs (one benefit of this is faster build times). You can learn more about how this code-generation model works by reading this tutorial.

Notice how the code-behind files for each page/user-control is still associated with the .aspx, .master and .ascx content. However, no .designer.cs files have been generated.

step2c

As part of our next step, we will be converting these pages to persist their partial class declarations on disk within a .designer.cs file.

Step 4: Converting the Project Files

To convert pages and classes within the project, right click the root node of the Web Application Project and select "Convert to Web Application". This will cause VS 2005 to recursively examine every page, user-control, and master-page in the project and automatically generate a .designer.cs file for each, as well as change the .aspx/.ascx files to use the "codebehind" rather than the "codefile" attribute. This command will also rename App_Code to Old_App_Code. When it’s completed your project will look as follows:

step2b

After you’ve added these files, build the project again to see if there are any compile errors. The most likely cause of errors at this stage are: a) You are missing an assembly reference, or b) You are using a dynamically generated type like the "Profile" object or a Typed DataSet. If you are missing an assembly reference, you should go to the reference manager and add it. If you are using a dynamically generated type, please see the Appendix of this tutorial for details on how to use it with the new VS 2005 Web Application Project option.

VERY, VERY IMPORTANT: Because ASP.NET 2.0 tries to dynamically compile any classes it finds under the /App_Code directory of an application at runtime, you explictly *DO NOT* want to store classes that you compile as part of your VS 2005 Web Application Project under an "app_code" folder. If you do this, then the class will get compiled twice — once as part of the VS 2005 Web Application Project assembly, and then again at runtime by ASP.NET. The result will most likely be a "could not load type" runtime exception — caused because you have duplicate type names in your application. Instead, you should store your class files in any other directory of your project other than one named "app_code". This will be handled automatically by the "Convert to Web Applicaiton" command. This command will rename the folder Old_App_Code.

Step 5: Running the Site

Once you have completed the above steps, you should be able to cleanly compile and run your application. By default it will use the built-in VS Web Server (aka Cassini) to run the site. You can alternatively configure the project to use IIS instead. To manage these settings, right-click on the project and pull up its project properties. You can then select the "Web" tab to configure these runtime settings:

step9

Step 6: Optionally Adding Namespaces

By default, pages and classes built within the VS 2005 Web Site Project option are not automatically added using a code namespace. Pages/Controls/Classes built using the VS 2005 Web Application Project option, on the other hand, do — so new pages/classes you add will by default have namespaces.

You can easily add namespaces in code to existing classes within VS using the "Surround With" context menu command in the C# code editor. Simply select a class (or multiple classes) in the source editor, then right click and select "Surround With->Namespace" option:

step10 step11 step12

Note that .aspx, .ascx, .master, .ashx, .asmx, and .asax files contain "inherits=" or "class=" attributes that list the class names they should invoke. So if you add namespaces to the code-behind files of these types you will also want/need to update the inherits and class declarations to also contain the namespace you use. For example: a Details.aspx page would need to have its page directive changed from "inherits=Details_aspx" to "inherits=WebApplication5.Details_aspx"

One easy way to bulk edit the namespace is to use Edit->Find and Replace command to find all inherits=" strings and change them to inherits="WebApplication. (note the trailing "." — which will be prepended before the previous class name).

Appendix 1: Migrating Declarative Typed DataSets (.xsd files)

If you have Strongly Typed DataSets under the App_Code directory in your VS 2005 Web Site Project, then you need to make an additional change to fixup the connection string in web.config.

Specifically, you need to open each DataSet in the Data Designer and select each TableAdapter and re-set the connectionstring for the object (you can do this by selecting the TableAdapter in the designer and then changing the "ConnectionString" property in the propertygrid).

Appendix 2: Migrating Code that works with the ASP.NET 2.0 Profile Object

ASP.NET 2.0 adds support for a new feature called "Profile Personalization". This enables developers to easily store and retrieve profile data about a user visiting the site within a personalization database. With VS 2005 Web Site Projects, ASP.NET automatically adds a strongly typed "Profile" object to each page in the project that provides a strongly-typed mapping of all properties defined within the "profile" section of the application’s web.config file. Developers can then get intellisense against this, and automatically save/retrieve values from it. For example, if an application’s web.config file had this section in it:

step17

Then developers could write this code within their pages to save/retrieve "Teachers" information:

step18

This is supported because with the VS 2005 Web Site Project option Visual Studio is dynamically creating and adding a "ProfileCommon" class named "Profile" into every code-behind instance.

Line numbers in code view in VS2005

Open Visual Studio 2005. Then go to Tools -> Options. Select "Text Editor" and the language you want to change the setting for.

image

VS2005 – Open folder or file in Explorer

Sometimes you just need to open the website you are working on in VS2005 in Explorer.

Well here is the trick of how to do it. Download and install the following

- Download Explorer add-in for VS2005

or read more about here

http://www.csharper.net/blog/_explore_in_windows__add_in_for_visual_studio_2005.aspx