EverydayHack

Code Snippet

For Each queue1 As PrintQueue In allqs

With Me.ListBox2.Items

.Add(queue1.Name)

End With

If queue1.NumberOfJobs > 0 Then

For Each job As PrintSystemJobInfo In queue1.GetPrintJobInfoCollection

alljobs.Add(job)

Next

End If

Next

The underlined code throws a "NullReferenceException was unhandled."

Thing is I know queue1 has jobs on it, and I know queue1.getprintjobinfocollection returns those jobs, so I don't understand where the null refrence could be. I can explore the queue value in debug mode and it shows me it has jobs.

<scratches head>




Re: Visual Basic Express Edition NullReferenceException - dumbfounded

Feng Chen - MSFT

Hi EverydayHack,

Could you please show the stack trace of the exception

Thanks!






Re: Visual Basic Express Edition NullReferenceException - dumbfounded

EverydayHack

This is a slightly different version of the program but same roadblock.... I opened the exception snapshot "system arguement null exception", then copied the text from the "stack trace".

Hope this is what you were looking for. If not please let me know, I'm a noob at all this....

" at MS.Internal.PrintWin32Thunk.GetDataThunkObject.PopulatePrintSystemObject(PrinterThunkHandler printingHandler, PrintSystemObject printObject, String[] propertiesFilter)
at System.Printing.PrintSystemJobInfo.PopulateJobProperties(String[] propertiesAsStrings)
at System.Printing.PrintSystemJobInfo..ctor(PrintQueue printQueue, Int32 jobIdentifier)
at System.Printing.PrintSystemJobInfo.Get(PrintQueue printQueue, Int32 jobIdentifier)
at WindowsApplication1.Form1.ListBox1_SelectionChanged(Object sender, EventArgs e) in G:\WindowsApplication3\WindowsApplication3\Form1.vb:line 103
at System.Windows.Forms.ListBox.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.ListBox.WmReflectCommand(Message& m)
at System.Windows.Forms.ListBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ListBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()"

Here is the most recent code I wrote trying to get around the error. Again, the underlined code is what throws the error (and the stack trace above).

Thanks a million for even taking a look at this.

Code Snippet

For Each queue1 As PrintQueue In allqs

With Me.ListBox2.Items

.Add(queue1.Name)

End With

index = 1

If queue1.NumberOfJobs > 0 Then

While index < queue1.NumberOfJobs

Dim smalljob As PrintSystemJobInfo

smalljob = PrintSystemJobInfo.Get(queue1, 1)

For Each job As PrintSystemJobInfo In queue1.GetPrintJobInfoCollection

MsgBox("adding job to alljobs")

alljobs.Add(job)

Next

End While

Else

End If

Next






Re: Visual Basic Express Edition NullReferenceException - dumbfounded

Feng Chen - MSFT

Hi EverydayHack,

Since the PrintSystemJobInfo is in .net framework 3.0 version and above, I'd like to know what exactly development environment you are using, and your system platform too.

Thanks!






Re: Visual Basic Express Edition NullReferenceException - dumbfounded

EverydayHack

I'm on a dell that I ran a clean windows XP installation on.... (not the dell branded but a full edition CD)

Ummmm I'm using Orcas but this error existed in 2005 as well....

I have no problem giving you the source, if it works on your machine then I'm sure I can figure out what is up on this one.

What more information would you like to know






Re: Visual Basic Express Edition NullReferenceException - dumbfounded

Feng Chen - MSFT

Hi EverydayHack,

Based on my research, this exception is actually a ArgumentNullException thrown by PrintWin32Thunk.GetDataThunkObject while it's checking the input arguments.

The following code can be seen from the .Net Reflectors (e.g. http://www.aisto.com/roeder/dotnet/), you can check which exactly argument is null and trace up the exception to see what's wrong.

Code Snippet
public bool PopulatePrintSystemObject(PrinterThunkHandler printingHandler, PrintSystemObject printObject, string[] propertiesFilter)
{
bool flag = false;
using (InfoLevelCoverageList coverageList = null)
{
if (printingHandler == null)
{
throw new ArgumentNullException("printingHandler");
}
if (printObject == null)
{
throw new ArgumentNullException("printSystemObject");
}
if (propertiesFilter == null)
{
throw new ArgumentNullException("propertiesFilter");
}
InfoLevelMask mask = TypeToLevelMap.GetCoverageMaskForPropertiesFilter(this.printingType, TypeToLevelMap.OperationType.Get, propertiesFilter);
if (mask != InfoLevelMask.NoLevel)
{
coverageList = this.BuildCoverageListAndGetData(printingHandler, mask);
if (coverageList == null)
{
return flag;
}
flag = this.PopulateAttributesFromCoverageList(printObject, propertiesFilter, coverageList);
}
}
return flag;
}

You can also post a simplest sample to reproduce the problem. You can remove any confidential information or business logic from it.

Thanks!






Re: Visual Basic Express Edition NullReferenceException - dumbfounded

Feng Chen - MSFT

Hi dumpfounded,

We are marking this issue as "Answered". If you have any new findings or concerns, please feel free to unmark the issue.

Thanks!






Re: Visual Basic Express Edition NullReferenceException - dumbfounded

EverydayHack

How would I go about unmarking it I'm still working on the advise you gave me and hope to post a response soon.

Regards,

EverydayHack

...edit...

Nevermind, I just realized I had to log in.

Still working on it my friend. Hope to have some stripped down code for you today.






Re: Visual Basic Express Edition NullReferenceException - dumbfounded

EverydayHack

Here is the simplest code sample I can come up with to reproduce the problem. The only business logic is in my message box, and I refuse to remove that. Smile

I apologize if these are obvious things but they wouldn't be to me:

You'll need to add a reference to system.printing for any of this to work.

You'll need two list boxes, listbox1, listbox2

You'll need one button

Other things not so obvious:

You need a locally defined printer. That means one physically connected to your machine or more specifically defined in your machine, to print to a port. Easiest route... go to printers add printer, next, local printer attached to this computer, do not check automatically search, choose lpt1, Manufacturer Panasonic, Printer Pan KX-P1081 - any printer name then add it. Do not print a test page. Put the print queue on pause, then print a test page.

This will leave a job in the queue so the code can find it.

The song lyrics mean all my other collections are working however, the next line is expected to crash.

Thoughts on my work so far:

Seems like I should be able to declare my variable alljobs like this: dimension alljobs as NEW printinfocollection - but it bombs out asking for a filter. I doní»t want to filter I want all of them - and even if I wanted to pass a blank filter I caní»t understand the syntax to do so.

I'm still studying objects, references, and when you needs a new instance, and what to do if there is no constructor. It might make more sense after I see what it takes to get this working, then again it might not.

The dotnet library here clearly states the printsystemjobinfo has class has no constructor. *shrug*

I greatly appreciate any assistance you can provide in this endeavor. Since I can't progress any further re-writing it from scratch I'm going to take a crack at your example code for tracing exceptions. Looks hairy though....

Code Snippet

Imports System.Printing

Public Class Form1

Dim allqs As New System.Printing.PrintQueueCollection

Dim allservers As New Microsoft.VisualBasic.Collection

Dim alljobs As System.Printing.PrintJobInfoCollection

Dim subjobs As New Microsoft.VisualBasic.Collection

Dim subqs As New Microsoft.VisualBasic.Collection

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

ListBox1.Items.Add("local")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim bacon As LocalPrintServer

bacon = New LocalPrintServer

allservers.Add(bacon)

For Each server1 As PrintServer In allservers

subqs.Add(server1.GetPrintQueues())

For Each qcoll As PrintQueueCollection In subqs

For Each queue1 As PrintQueue In qcoll

With Me.ListBox2.Items

.Add(queue1.Name)

End With

If queue1.NumberOfJobs > 0 Then

MsgBox("I got my haircut, by a jumbojet. It wasn't easy, but nothing is. No.")

subjobs.Add(queue1.GetPrintJobInfoCollection)

For Each job As PrintSystemJobInfo In queue1.GetPrintJobInfoCollection

alljobs.Add(job)

Next

End If

Next

Next

Next

End Sub

End Class

Comments, criticisms, obscenities, and hurled tomatoes are welcome.






Re: Visual Basic Express Edition NullReferenceException - dumbfounded

Junner2003

EveryDayHack,

whenever I got similar errors it was enough just to disable CAUSES VALIDATION in the properties of the specific control - give it a try, it cn't hurt!





Re: Visual Basic Express Edition NullReferenceException - dumbfounded

Kodavati

hi,

i encountered the same exception when dealing with listboxes.

here is my code.


For index = 0 To movies_name.Items.Count
If movies_name.SelectedIndex Then
MessageBox.Show(movies_name.Text)
str(j) = movies_name.Text
j = j + 1
End If

i am trying to retrieve multiple selected items from a list box and i get the following error on the underlined line

"Object reference not set to an instance of an object."

Can u please tell me where i could have gone wrong

i have tried turning out Validating to off but it did not work