Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 320898 - Last Review: February 9, 2004 - Revision: 3.1
FIX: NullReferenceException When You Print in Windows 98 or Windows Millennium Edition
This article was previously published under Q320898
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)
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Â
(http://kbalertz.com/Feedback.aspx?kbNumber=318836/EN-US/
)
INFO: How to Obtain the Latest .NET Framework Service Pack
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, "In PrintPage" );
string line = new string( 'J', 1 );
Font printFont = new Font("Arial", 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 "Symptoms" section.
APPLIES TO
- Microsoft .NET Framework 1.0
| kbbug kbfix kbqfe KB320898 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate