Microsoft KB Archive/320898

= FIX: NullReferenceException When You Print in Windows 98 or Windows Millennium Edition =

Article ID: 320898

Article Last Modified on 2/9/2004

-

APPLIES TO


 * Microsoft .NET Framework 1.0

-



This article was previously published under Q320898



SYMPTOMS
When you use the PrintDocument class to print, a NullReferenceException exception occurs in System.Windows.Forms.BackgroundThread.UpdateLabel on computers that are running Microsoft Windows 98 or Microsoft Windows Millennium Edition (Me).

The PrintPreview class can also cause this problem.

The following text appears in the exception details:

************** Exception Text ************** System.NullReferenceException: Object reference not set to an instance of an object. at System.Windows.Forms.BackgroundThread.UpdateLabel at System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPage(PrintDocument document, PrintPageEventArgs e)  at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument document) at System.Drawing.Printing.PrintController.Print(PrintDocument document) at System.Drawing.Printing.PrintDocument.Print at PrintingExample.printButton_Click(Object sender, EventArgs e) in c:\source\delmeone\form1.cs:line 34 at System.Windows.Forms.Control.OnClick(EventArgs e)  at System.Windows.Forms.Button.OnClick(EventArgs e)   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m)  at System.Windows.Forms.ButtonBase.WndProc(Message& m)   at System.Windows.Forms.Button.WndProc(Message& m)   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)



RESOLUTION
To resolve this problem, obtain the latest service pack for Microsoft .NET Framework. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

318836 INFO: How to Obtain the Latest .NET Framework Service Pack



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was first corrected in Microsoft .NET Framework Service Pack 2 (SP2). This problem is resolved in the release of the .NET Framework that will coincide with the version 7.1 release of Visual Studio .NET.



Steps to Reproduce the Behavior
 Install the Microsoft .NET Framework on a computer that is running Microsoft Windows 98, and then install a printer on this computer. Create a new Visual C# Windows Application project that uses code that is similar to the code in the PrintDocument documentation.  Drag a Button control from the toolbox to the form, and then add the following code to the Click event handler of the Button: PrintDocument pd = new PrintDocument; pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); pd.Print;   Add the following method to the form: private void pd_PrintPage(object sender, PrintPageEventArgs ev) {   MessageBox.Show( this, &quot;In PrintPage&quot; ); string line = new string( 'J', 1 ); Font printFont = new Font(&quot;Arial&quot;, 10 ); ev.Graphics.DrawString(line, printFont, Brushes.Black, ev.MarginBounds.Left, 0, new StringFormat); ev.HasMorePages = false; }                    Save and then run the project. Notice that instead of printing the page, you receive an exception and the call stack that is listed in the &quot;Symptoms&quot; section.</li></ol>

Additional query words: stack dump

Keywords: kbbug kbfix kbqfe KB320898

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.