dotnet / dotnet/wpf

An exception occurred while populating the properties for the PrintQueue object. Win32 error: The data area passed to a system call is too small.

Open
#4,540 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

```
WINCLIENT (Win10) <----> Server 2019

* WINCLIENT has a printer (imc2k) which is shared to the server, so that it can access it.

* Server 2019 runs service + web. Server has the \\winclient\imc2k printer added. and also a local printer imc2k created pointing to WINCLIENT to simulate workgroup printing.
```

Service with a web part in .NET 5

We receive:

```
An exception occurred while populating the properties for the PrintQueue object. Win32 error: The data area passed to a system call is too small.
```

simulation of code:

```
//printer is shared from \\WINCLIENT\imc2k
var serverName = "WINCLIENT";
var printerName = "imc2k";
using(var server = new PrintServer(serverName)
using(var queue = new PrintQueue(server, printerName, PrintSystemDesiredAccess.UsePrinter)) //<- here crash
{
var cap = queue.GetPrintCapabilities();
}
```

This code runs on Server 2019 Version 1809 OS Build 17763.1911.

```
>dotnet --info

Host (useful for support):
Version: 5.0.0
Commit: cf258a14b7

.NET SDKs installed:
No SDKs were found.

.NET runtimes installed:
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

```

The printer is shared on a Windows 10 Version 20H2 OS Build 19042.985.

it's queue is paused,

The server has \\WINCLIENT\imc2k but also a local printer using tcp/ip port pointing to WINCLIENT (simulating workgroup printing).

Where the error happens is a combobox showing the two printers and settings (so can't figure out on which printer it happens).

```
// imc2k on the WINCLIENT pc:

Driver Name: PCL6 V4 Driver for Univeral Print
Driver version: 4.4.0.0
Driver type: Type 4 - User Mode
Share name: imc2k

Port is a Standard TCP/IP Port Write
```

When looking at https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d it looks like this is an `ERROR_INSUFFICIENT_BUFFER`.

So I guess that the handling of the `ERROR_INSUFFICIENT_BUFFER` isn't good in .NET 5 when looking at this:
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-prsod/c5d04584-e3da-4faf-befa-614f9fac6760

(this document is about workgroup printing, and our local port was added to simulate workgroup printing, thus might sound logically.)

> If the number of shared print queues on the server has increased between the first and second call to RpcEnumPrinters, the server also returns ERROR_INSUFFICIENT_BUFFER from the second call. In that case, the server updates the countBytesNeeded parameter so that the client can reallocate the buffer and repeat the call to RpcEnumPrinters.

For now this is all I can give you, as it happens in production, not in other environment.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.