Why System.Printing namespace are not supported for use within a Windows service or ASP.NET application or service.

Jing Hong Lee 0 Reputation points
2024-01-09T00:44:50.79+00:00

https://learn.microsoft.com/en-us/dotnet/api/system.printing?view=windowsdesktop-8.0

Why the System.Printing show this caution box in the documentation, any references or detailed information?User's image

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,256 questions
Windows Server Printing
Windows Server Printing
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Printing: Printer centralized deployment and management, scan and fax resources management, and document services
640 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lan Huang-MSFT 25,556 Reputation points Microsoft Vendor
    2024-01-09T07:03:08.0133333+00:00

    Hi @Jing Hong Lee,

    Are you wondering why it is not recommended to use classes from the System.Printing namespace in Windows Services or ASP.NET applications or services?

    Based on the warning message, it's clear that trying to use classes in the System.Printing namespace from a Windows service or ASP.NET application or service may cause unexpected problems, such as service degradation and runtime exceptions.

    I didn't find any more information about the official documentation at the moment. But I have seen related explanations:

    The System.Printing assembly is dependent upon WPF. WPF is not usable inside a service because a service does not have a UI. It also doesn't make sense in ASP.NET because a UI wouldn't be seen from the client. The documentation doesn't say it won't work, it just says that it may not work as expected and that is because of the WPF underpinning. For example under the hood some of the classes rely on the Dispatcher from WPF. You'll likely only have a single Dispatcher (because that is traditionally the UI thread) so your multi-threaded service/ASP.NET app will be serialized down to a single thread for some calls. This will kill performance and may (depending upon the thread) cause a failure.Therefore, System.Printing show this caution box in the documentation.

    Links that may be helpful:

    https://learn.microsoft.com/en-us/answers/questions/358550/c-printing-problem-with-system-drawing-printing-fr

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Bruce (SqlWork.com) 56,026 Reputation points
    2024-01-09T16:45:14.4866667+00:00

    many of the printer support classes make use of the user's profile data. to access known printers for example. a service does not have a user profile.