System.Printing not found( C# )?

旧时模样 提交于 2020-08-10 04:36:09

问题


I am trying to run the following example from MSDN:

using System.Printing;

public class PrintTest {
public static void Main(string[] args)
{
    // Create the printer server and print queue objects
    LocalPrintServer localPrintServer = new LocalPrintServer();
    PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue();

    // Call AddJob
    PrintSystemJobInfo myPrintJob = defaultPrintQueue.AddJob();

    // Write a Byte buffer to the JobStream and close the stream
    Stream myStream = myPrintJob.JobStream;
    Byte[] myByteBuffer = UnicodeEncoding.Unicode.GetBytes("This is a test string for the print job stream.");
    myStream.Write(myByteBuffer, 0, myByteBuffer.Length);
    myStream.Close();
    }
}

but the compiler is complaining

The type or namespace Printing does not exist in the namespace System(are you missing an assembly reference) ?

How do I solve this issue ?

EDIT: How do I add a reference for command line compiled application ( Not Visual Studio)


回答1:


From the command line something like csc /reference:lib\System.Printing.dll


Original Answer

Project > Add Reference, then under 'Assemblies > Framework'.

Choose System.Printing.

You can find out which Assembly you need to add a reference to by Googling the namespace followed by the word 'assembly'. In your case:

System.Printing assembly

The second result is from MSDN and indicates which assembly System.Printing can be found in.





回答2:


From Command prompt Create a public reference

/reference:[alias=]filename
/reference:filename

Where

Arguments


filename
The name of a file that contains an assembly manifest. To import more than one file, include a separate /reference option for each file.

alias
A valid C# identifier that will represent a root namespace that will contain all namespaces in the assembly.

Microsoft documentation page for cmd

From Visual Studio Community 2013 (Free version) Right click References folder in your solution and browse for it there. Step 1 how to add assembly referenceStep 2 how to add assembly reference




回答3:


You are missing an assembly reference. Add a reference to System.Printing.dll.




回答4:


You need to add the System.Printing assembly to your project.

http://i.imgur.com/0Abo17N.png

You can find this by right clicking on your project and clicking "Add Reference". (You can search for it in the Assemblies > Framework tab)

Additionally, you must add using System.IO; in order to use Stream.




回答5:


In your Solution Explorer right click on References click on Add Reference click on the .NET tab and scroll to System.Drawing. It should work.




回答6:


Original answer found here:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/0648fdc4-f67b-476e-b434-998efec14b89/class-systemprintingprintcapabilities-not-found?forum=wpf

However, you'll need to add the Assembly called ReachFramework



来源:https://stackoverflow.com/questions/31101704/system-printing-not-found-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!