Microsoft KB Archive/837222

= You receive a &quot;NullReferenceException&quot; error message or an &quot;OutOfMemoryException&quot; error message when you run the MultiThreaded TCP/IP Listener sample application in Visual Studio .NET =

Article ID: 837222

Article Last Modified on 5/17/2007

-

APPLIES TO


 * 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

-





SYMPTOMS
In Microsoft Visual Studio .NET, when you run the application that is associated with the &quot;Windows Forms: Multi-Threaded TCP/IP Listener sample&quot; Help topic, the Microsoft Windows Form that is named Client may close unexpectedly and you may receive one or more of the following error messages:

Message 1

An unhandled exception of type 'System.NullReferenceException' occurred in Client.exe

Additional information: Object reference not set to an instance of an object.

Message 2

An unhandled exception of type 'System.OutOfMemoryException' occurred in system.windows.forms.dll

Additional information: Too many items in list box.

Note If you are using Visual Studio .NET 2003, and you follow the instructions that appear in the &quot;To run this sample&quot; section of the &quot;Windows Forms: Multi-Threaded TCP/IP Listener Sample&quot; Help topic, this behavior does not occur because the Visual Studio .NET 2003 Help topic contains the correct instructions to run the sample.



CAUSE
The application that is associated with the &quot;Windows Forms: Multi-Threaded TCP/IP Listener sample&quot; Help topic is a solution that contains multiple projects.

In Microsoft Visual Studio .NET 2003, this problem occurs because the startup configuration for the projects is incorrectly set to Start instead of to Start without debugging.

In Microsoft Visual Studio .NET 2002, this problem occurs because the startup configuration for the solution is incorrectly set to Single Startup Project instead of to Multiple Startup Projects.



WORKAROUND
To work around this problem, change the configuration settings for your solution or for your projects. To do this, follow these steps:
 * 1) In Visual Studio .NET, open the TCPIPListener solution.
 * 2) In Solution Explorer, right-click the solution, and then click Properties. The Solution 'TCPIPListener' Property Pages dialog box appears.
 * 3) Click the Multiple Startup Projects option.
 * 4) Under Project, click Client.
 * 5) In the Action field of the Client project, click Start without debugging.
 * 6) Under Project, click Listener.
 * 7) In the Action field of the Listener project, click Start without debugging.
 * 8) Click OK.
 * 9) On the Debug menu, click Start Without Debugging.



Visual Studio .NET 2003
To reproduce the behavior that appears in the &quot;Symptoms&quot; section, follow these steps:
 * 1) In Visual Studio .NET 2003, open the TCPIPListener solution. This solution is located in the  \Vb7\VB Samples\WinForms-Threads-TCPListener\TCPIPListener folder.

Note  is a placeholder for the absolute path of the folder where Visual Studio .NET is installed.
 * 1) On the Debug menu, click Start. The Client Windows Form and the Listener Windows Form appear.
 * 2) Close the Listener Windows Form.

The behavior that appears in the &quot;Symptoms&quot; section of this article may occur.

Visual Studio .NET 2002
To reproduce the behavior that appears in the &quot;Symptoms&quot; section, follow these steps:
 * 1) In Visual Studio .NET 2002, open the TCPIPListener solution. This solution is located in the  \Vb7\VB Samples\WinForms-Threads-TCPListener\TCPIPListener folder.

Note  is a placeholder for the absolute path of the folder where Visual Studio .NET is installed.
 * 1) On the Debug menu, click Start. The Client Windows Form appears.
 * 2) Click Start, and then click Stop. Do this more than one time.

The behavior that appears in the &quot;Symptoms&quot; section of this article may occur.

