Bug 34123 - System.Drawing.Printing fails on Mac OSX Yosemite
Summary: System.Drawing.Printing fails on Mac OSX Yosemite
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Drawing ()
Version: 4.0.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-09-21 13:13 UTC by Guerry Semones
Modified: 2015-09-23 17:01 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Solution to reproduce printing issue on Yosemite. (3.08 KB, application/zip)
2015-09-21 13:13 UTC, Guerry Semones
CUPS log of failed print run (22.82 KB, application/octet-stream)
2015-09-21 13:15 UTC, Guerry Semones

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 34123 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Guerry Semones 2015-09-21 13:13:12 UTC
Created attachment 12993 [details]
Solution to reproduce printing issue on Yosemite.

This may be related to bug 27160, which also reports an issue with System.Drawing on Yosemite.

I've attached a solution with a very simple printing example. I have a Yosemite machine (10.10.4) and a Mavericks machine (10.9.5), both running Xamarin Studio 5.9.7 (build 9), the latest stable as of this post.

When the printing code runs on Mavericks via Mono 4.0.4 or Mono 3.12.1, the print job succeeds. 

When run on Yosemite with either or 3.12.1, the print job does not print. Unlike bug 27160, no exception is thrown, or at least no exception that percolates up to my code.

I've never set up a Mono environment, but I'll try and debug my way into System.Drawing. Meanwhile, any help is appreciated.

Examining the CUPS logs, we see the following. The print job is added (first line of log) and then immediately canceled (last line of log). I'll attach the full event log of this print run.

D [21/Sep/2015:11:40:52 -0500] add_job: requesting-user-name="guerry"
D [21/Sep/2015:11:40:52 -0500] Adding default job-sheets values "none,none"...
I [21/Sep/2015:11:40:52 -0500] [Job 46] Adding start banner page "none".
D [21/Sep/2015:11:40:52 -0500] Discarding unused job-created event...
I [21/Sep/2015:11:40:52 -0500] [Job 46] Queued on "_192_168_192_5" by "guerry".
D [21/Sep/2015:11:40:52 -0500] [Client 50] Returning IPP successful-ok for Create-Job (ipp://localhost:631/printers/_192_168_192_5) from localhost
D [21/Sep/2015:11:40:52 -0500] [Client 50] Content-Length: 178
D [21/Sep/2015:11:40:52 -0500] [Client 50] cupsdSendHeader: code=200, type="application/ipp", auth_type=0
D [21/Sep/2015:11:40:52 -0500] [Client 50] con->http=0x7ffea401a600
D [21/Sep/2015:11:40:52 -0500] [Client 50] cupsdWriteClient error=0, used=0, state=HTTP_STATE_POST_SEND, data_encoding=HTTP_ENCODING_LENGTH, data_remaining=178, response=0x7ffea3c86420(IPP_STATE_IDLE), pipe_pid=0, file=-1
D [21/Sep/2015:11:40:52 -0500] [Client 50] Writing IPP response, ipp_state=IPP_STATE_DATA, old wused=0, new wused=0
D [21/Sep/2015:11:40:52 -0500] [Client 50] bytes=0, http_state=0, data_remaining=178
D [21/Sep/2015:11:40:52 -0500] [Client 50] Flushing write buffer.
D [21/Sep/2015:11:40:52 -0500] [Client 50] New state is HTTP_STATE_WAITING
D [21/Sep/2015:11:40:52 -0500] [Client 50] Waiting for request.
D [21/Sep/2015:11:40:52 -0500] cupsdSetBusyState: newbusy="Dirty files", busy="Active clients and dirty files"
D [21/Sep/2015:11:40:52 -0500] [Client 50] HTTP_STATE_WAITING Closing for error 32 (Broken pipe)
D [21/Sep/2015:11:40:52 -0500] [Client 50] Closing connection.
D [21/Sep/2015:11:40:52 -0500] cupsdSetBusyState: newbusy="Dirty files", busy="Dirty files"
D [21/Sep/2015:11:40:52 -0500] [Client 51] Accepted from localhost (Domain mono-sgen[72861])
D [21/Sep/2015:11:40:52 -0500] [Client 51] Waiting for request.
D [21/Sep/2015:11:40:52 -0500] [Client 51] POST /jobs/ HTTP/1.1
D [21/Sep/2015:11:40:52 -0500] cupsdSetBusyState: newbusy="Active clients and dirty files", busy="Dirty files"
D [21/Sep/2015:11:40:52 -0500] [Client 51] Read: status=200
D [21/Sep/2015:11:40:52 -0500] [Client 51] No authentication data provided.
D [21/Sep/2015:11:40:52 -0500] [Client 51] 2.0 Cancel-Job 7
D [21/Sep/2015:11:40:52 -0500] Cancel-Job ipp://localhost:631/printers/_192_168_192_5
D [21/Sep/2015:11:40:52 -0500] cupsdIsAuthorized: requesting-user-name="guerry"
D [21/Sep/2015:11:40:52 -0500] [Job 46] time-at-completed=1442853652
D [21/Sep/2015:11:40:52 -0500] Discarding unused job-completed event...
I [21/Sep/2015:11:40:52 -0500] [Job 46] Job canceled by "guerry"


Comment 1 Guerry Semones 2015-09-21 13:15:16 UTC
Created attachment 12994 [details]
CUPS log of failed print run

I was not sure if this would be helpful or not.
Comment 2 Guerry Semones 2015-09-22 18:05:27 UTC
Okay, I built mono on my Maverick and Yosemite macs, and then debugged my sample app (attached previously). This is what I learned....

In the CreateGraphicsContext method of System.Drawing.Printing.PrintingServicesUnix, line 846, cupsTempFile(sb, length) is called, and cups is supposed to return a temporary file name. 

	cupsTempFile (sb, length);
        name = sb.ToString ();

This file name is used by the DOCINFO structure at line 869:
	DOCINFO doc = new DOCINFO ();
	doc.filename = name;

 The DOCINFO later passes the filename to cupsPrintFile at line 816:

	cupsPrintFile (doc.settings.PrinterName, doc.filename, doc.title, options_count, options);

It is at this call that the print job is submitted, and prints on Maverick and is cancelled on Yosemite. On Yosemite, cupsTempFile(sb, length) return an empty string. On Maverick, it returns a file name.

cupsTempFile is a DllImport:

	[DllImport("libcups", CharSet=CharSet.Ansi)]
	static extern IntPtr cupsTempFile (StringBuilder sb, int len);

I do not know enough about mono internals to know if this is a mono bindings issue, or a Yosemite bug.

Any comments or thoughts?


Comment 3 Guerry Semones 2015-09-22 18:08:51 UTC
Upon further googling, it appears that cupsTempFile is deprecated and not supported in CUPS 2.0.0 and OSX 10.10.*

I will look for recommended alternatives and see if I can't put together a pull request.


Comment 4 Guerry Semones 2015-09-23 11:41:58 UTC
Okay, I have the solution, and its very simple.

CUPS deprecated cupsTempFile a long time back. Looking over their documentation, cupsTempFd has an identical method footprint and is not deprecated. I replaced the call to cupsTempFile with cupsTempFd on both my Mavericks and Yosemite builds of net_4_x (master), and was able to print on Yosemite and Mavericks.

Now I need to figure out how to get this fix into mono.... Directions welcome. :-)


Comment 5 Guerry Semones 2015-09-23 12:40:37 UTC
Preparing a pull request on github....
Comment 6 Guerry Semones 2015-09-23 14:47:18 UTC
I posted a pull request with the fix here:
Comment 7 Guerry Semones 2015-09-23 17:01:26 UTC
I received notification that the pull request has been merged into mono:master.