Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve System.Drawing.Printing

Tags:

c#

.net

I am trying to display a list of installed printers on the local computer using the method described on MSDN ...

using System.Drawing;
using System.Drawing.Printing;

namespace SandBox
{
    class Program
    {
        static void Main(string[] args)
        {

            for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
            {
                Console.WriteLine(PrinterSettings.InstalledPrinters[i]);        
            }

            Console.ReadLine();
        }
    }
}

The problem is on the Using statement, the 'Printing' namespace cannot be resolved. Is there an additional reference I am missing?

UPDATE: I have added references to System.Drawing & System.Printing but this does not resolve the problem.

like image 756
philreed Avatar asked Dec 11 '22 16:12

philreed


2 Answers

In order to use the System.Drawing.Printing namespace, you must reference the assembly System.Drawing.dll

like image 56
Cyril Gandon Avatar answered Dec 14 '22 04:12

Cyril Gandon


In .Net Core and .Net Standard, System.Drawing.Printing can be installed via nuget Microsoft.Windows.Compatibility

Docs: https://learn.microsoft.com/en-us/dotnet/core/porting/windows-compat-pack

like image 34
CannabiS Avatar answered Dec 14 '22 05:12

CannabiS