简体   繁体   中英

System.Drawing.Printing: The RPC server is unavailable

I'm running some really basic print code: (using .net 4.0, VS 2012, Windows 8)

var bitmap = new Bitmap(control.Width, control.Height);

control.DrawToBitmap(bitmap, new Rectangle(0, 0, control.Width, control.Height));

var pd = new PrintDocument();

pd.PrintPage += (s, e) => e.Graphics.DrawImage(bitmap, 100, 100);
pd.Print();

And it is throwing an error:

System.ComponentModel.Win32Exception was unhandled
HResult=-2147467259
Message=The RPC server is unavailable
  Source=System.Drawing
  ErrorCode=-2147467259
  NativeErrorCode=1722
  StackTrace:
   at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
   at System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument document, PrintEventArgs e)
   at System.Drawing.Printing.PrintController.Print(PrintDocument document)
   at System.Drawing.Printing.PrintDocument.Print()
   at FrogJump.Form1.PrintControl(Control control) in e:\Univ\S13\AI\FrogJump\FrogJump\Form1.cs:line 120
   at FrogJump.Form1.btnPrint_Click(Object sender, EventArgs e) in e:\Univ\S13\AI\FrogJump\FrogJump\Form1.cs:line 108
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at FrogJump.Program.Main() in e:\Univ\S13\AI\FrogJump\FrogJump\Program.cs:line 18
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
InnerException: 

It is really a long shot - but I think you should check if you are printing to the printer you think you are printing to.. ;)

(check if you are printing to the correct printer and it is turned on)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM