System.Drawing.Printing:RPC服务器不可用

3
我正在运行一些非常基本的打印代码:(使用 .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();

它出现了一个错误:

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: 

System.Drawing.Printing和Windows打印API都不使用RPC。你需要先检查一下打印机驱动程序。 - undefined
1个回答

5

这可能是一个冒险的想法 - 但我认为你应该检查一下你是否在打印到你想打印的打印机上.. ;)

(检查一下你是否在打印到正确的打印机上,且它已经开启)


实际上你的评论帮了大忙!突然间错误就消失了!当时我的电脑没有连接“默认打印机”...仍然不明白为什么会出现错误,但目前至少问题解决了。:) 谢谢!! - undefined
说实话,这并不是一个"真正"的高难度任务.. :) 你想要打印,但在这种情况下唯一使用远程过程调用(RPC)的地方就是打印机驱动程序试图向服务器(打印机)发送命令,而服务器很可能无法连接.. "Message=RPC 服务器不可用" - undefined
对我来说,重新启动打印池服务解决了这个问题。 - undefined
2
+1 - 这个答案对于这类问题来说是一个很好的起点。在我的情况下,我试图从一个未连接到域的虚拟机上运行的.NET应用程序中进行打印,所以我猜我没有被授权访问我尝试打印的服务器。通过Windows资源管理器访问该服务器时,提示我输入凭据,一旦缓存后,从.NET应用程序中进行打印就可以正常工作了。不过,这个错误信息真是一点帮助都没有! - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接