Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PrintServer.GetPrintQueues throws NullReferenceException #8339

Open
wstaelens opened this issue Oct 20, 2023 · 5 comments
Open

PrintServer.GetPrintQueues throws NullReferenceException #8339

wstaelens opened this issue Oct 20, 2023 · 5 comments

Comments

@wstaelens
Copy link
Contributor

Description

when calling GetPrintQueues I sometimes get a NullReferenceException (not always)

Reproduction Steps

          var server = new System.Printing.PrintServer();
        var queues = server.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });

Expected behavior

never having a nullreference exception

Actual behavior

sometimes (don't know how to reproduce it) I get a NullReferenceException. (feels like it happens the first time something needs to be initialised.)

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

.net 7 latest
windows 10 x64 22h2
vs2022 pro any cpu

Other information

when looking at https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/System.Printing/ref/System.Printing.cs#L393 I see that it throws null, but I have print queues as a result, sometimes it throws null, but don't know why exactly.

@lindexi
Copy link
Contributor

lindexi commented Oct 22, 2023

@wstaelens https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/System.Printing/ref/System.Printing.cs#L393 is the reference project. In other words, it do not run in the user's devices. So I do not think it will cause any issues.

It will be helpful, if you can append the exception stacktrace.

@singhashish-wpf singhashish-wpf added the 📭 waiting-author-feedback To request more information from author. label Oct 23, 2023
@wstaelens
Copy link
Contributor Author

wstaelens commented Oct 23, 2023

well the strange thing is that we sometimes get a nullreference.
I'll try to see if I can get a stacktrace. Onlything is that I can't force it to reproducing it.

If feels like it happens when something is taking too much time or is initializing. Because 99% of the time I get the queues but sometimes i get that null result. (don't know if it might be related to VS and its debugging context or not)

@ghost ghost removed the 📭 waiting-author-feedback To request more information from author. label Oct 23, 2023
@wstaelens
Copy link
Contributor Author

stacktrace:

   at System.Printing.Activation.PrintSystemObjectFactory.Instantiate(Type objType, String[] propertiesFilter)
   at MS.Internal.PrintWin32Thunk.EnumDataThunkObject.GetPrintSystemValuesPerPrintQueues(PrintServer printServer, EnumeratedPrintQueueTypes[] flags, Queue`1 printObjectsCollection, String[] propertyFilter)
   at System.Printing.PrintQueueCollection..ctor(PrintServer printServer, String[] propertyFilter, EnumeratedPrintQueueTypes[] enumerationFlag)
   at System.Printing.PrintServer.GetPrintQueues(EnumeratedPrintQueueTypes[] enumerationFlag)
   at <hidden>.InstalledPrinters() in <hidden>\PrinterSettingsEx.cs:line 153

@lindexi
Copy link
Contributor

lindexi commented Oct 23, 2023

@wstaelens It seems that you are using a disposed PrintSystemObjectFactory object.

@wstaelens
Copy link
Contributor Author

Just calling GetPrintQueues so don't see why it is disposed or why i'm using disposed one.
Something strange is happening.

I've noticed that sometimes after adding a new printer, the Windows Control panel freezes and after 30seconds or a few minutes it loads fine. Must be something in Windows which has been changed and maybe relates to this. Anyone else experiencing thing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants