Microsoft KB Archive/317790

= How to debug multilanguage applications in Visual Studio .NET =

Article ID: 317790

Article Last Modified on 3/3/2006

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition

-



This article was previously published under Q317790



IN THIS TASK
SUMMARY
 * Requirements
 * Use the Enhanced Debugger in Visual Studio .NET Multilanguage Debugging
 * Verify That It Works
 * Next Steps
 * Complete Code Listing - WebForm1.aspx
 * Complete Code Listing - WebForm1.aspx.vb
 * Complete Code Listing - Class1.cs

REFERENCES



SUMMARY
This article shows how to debug a multiproject, multilanguage solution that consists of a Microsoft Visual Basic .NET Web Service and a Microsoft C# class library that simulates the data tier.

back to the top

Requirements
The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
 * Microsoft Windows 2000 Professional (or Server), or Microsoft Windows XP Professional (or Server) with the .NET Framework installed.

This article assumes that you are familiar with the following topics:
 * The Visual Studio debugger and basic debugging concepts.

back to the top

Use the Enhanced Debugger in Visual Studio .NET Multilanguage Debugging
 Open Visual Studio .NET. On the File menu, point to New, and then click Project. In the New Project dialog box, select Visual Basic Projects from Project Types. In Templates, select ASP.NET Web Application. In the Location textbox, replace &quot;WebApplication1&quot; with &quot;HowToDebug&quot;. Click OK. We now have the shell of a Visual Basic .NET Web application in a solution named &quot;HowToDebug&quot;. To make this a multilanguage solution, we'll add a Visual C# class library:

 In the Solution Explorer, right-click the HowToDebug solution, click Add, and then click New Project. Select Visual C# Projects. In Templates, select Class Library. In the Name text box, you should see &quot;HowToClassLib&quot;. Click OK to add the project to the solution.  Class1.cs should now be open in the Code Editor window. Add two namespace declarations at the top in order to have shorthand access to the classes in them: using System.Data; using System.Data.SqlClient;   Replace the public Class1 method with the following method that returns a DataSet from the Northwind database: public static DataSet GetProducts(string CategoryID) {           DataSet ds = new DataSet; SqlDataAdapter sqlDS = new SqlDataAdapter(&quot;select * from products where categoryid=&quot; + CategoryID, new SqlConnection(&quot;server=localhost;database=northwind;uid=sa&quot;)); sqlDS.Fill(ds); return ds; }                   </li> In the Solution Explorer, expand the HowToDebug project, right-click WebForm1.aspx, and then select View Designer.</li> Press F4 to access the Properties window. Change the pageLayout property to FlowLayout.</li> Click Web Form and type &quot;CategoryID: &quot;. Press CTRL+ALT+X to open the toolbox. In the toolbox, select Web Forms. Drag a text box and a button to the Web Form. Press F4 to access the Properties window for the button. Change the Text Property to &quot;Get Products&quot;.</li> Press Enter to create a new line on the Web Form. From the toolbox, drag a DataGrid control to the Web Form.</li> Double-click the Button to create a Click event handler in the Web Form's codebehind class. This is where we will place the code to call the GetProducts method. Before we add the code to the handler, however, we need to add a reference to the C# class library.</li> In the Solution Explorer, under HowToDebug, right-click References and click Add Reference.</li> Click the Projects tab; HowToClassLib should be selected. Click Select and HowToClassLib should appear in the Selected Components list box. Click OK. You should now see HowToClassLib listed under References for the HowToDebug project.</li>  Add the following code to the Button1_Click event handler: DataGrid1.DataSource =  HowToClassLib.Class1.GetProducts(TextBox1.Text) DataGrid1.DataBind </li></ol>

Verify That It Works

 * 1) Press F5 to run the application in debug mode.
 * 2) When the page loads, type &quot;2&quot; in the CategoryID field and then click GetProducts.
 * 3) The DataGrid should fill with the results of the query.
 * 4) Close the browser to stop debugging and return to Visual Studio .NET.

back to the top

Next Steps

 * 1) In the Code Editor window, place your cursor on the Button1_Click event declaration. Press F9 to set a breakpoint.
 * 2) Click the Class1.cs tab. Set a breakpoint at the GetProducts method.
 * 3) Press F5 to run the application in debug mode.
 * 4) When the page loads, type &quot;2&quot; in the CategoryID field and then click GetProducts.
 * 5) The application will stop at the Button1_Click event handler. Press F11 to step into the code.
 * 6) Press F11 again. Note that the debugger seamlessly shifted to the C# method being called by the Visual Basic .NET event handler.
 * 7) Continue to press F11 until control is returned to the event handler.
 * 8) Press F5 to finish running the application. The DataGrid should fill with the results of the query.

back to the top

Complete Code Listing - WebForm1.aspx
<%@ Page Language=&quot;vb&quot; AutoEventWireup=&quot;false&quot; Codebehind=&quot;WebForm1.aspx.vb&quot; Inherits=&quot;HowToDebug.WebForm1&quot;%> <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;> <HTML> <HEAD> WebForm1 <meta name=&quot;GENERATOR&quot; content=&quot;Microsoft Visual Studio.NET 7.0&quot;> <meta name=&quot;CODE_LANGUAGE&quot; content=&quot;Visual Basic 7.0&quot;> <meta name=vs_defaultClientScript content=&quot;JavaScript&quot;> <meta name=vs_targetSchema content=&quot;http://schemas.microsoft.com/intellisense/ie5&quot;> </HEAD>

<form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;> <P>CategoryID: <asp:TextBox id=&quot;TextBox1&quot; runat=&quot;server&quot;></asp:TextBox> <asp:Button id=&quot;Button1&quot; runat=&quot;server&quot; Text=&quot;Get Products&quot;></asp:Button></P> <P> <asp:DataGrid id=&quot;DataGrid1&quot; runat=&quot;server&quot;></asp:DataGrid></P>

</HTML>

back to the top

Complete Code Listing - WebForm1.aspx.vb
Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid


 * 1) Region &quot; Web Form Designer Generated Code &quot;

'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough> Private Sub InitializeComponent

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent End Sub


 * 1) End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here. End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DataGrid1.DataSource = HowToClassLib.Class1.GetProducts(TextBox1.Text) DataGrid1.DataBind End Sub End Class back to the top

Complete Code Listing - Class1.cs
using System; using System.Data; using System.Data.SqlClient;

namespace HowToClassLib {   ///     /// Summary description for Class1. ///    public class Class1 {       public static DataSet GetProducts(string CategoryID) {           DataSet ds = new DataSet; SqlDataAdapter sqlDS = new SqlDataAdapter(&quot;select * from products where categoryid=&quot; + CategoryID, new SqlConnection(&quot;server=localhost;database=northwind;uid=sa&quot;)); sqlDS.Fill(ds); return ds; }   } } back to the top