1

I have a C# console application that I want to run on Linux. I've compiled it in MonoDevelop and on my machine (Ubuntu 12.04 LTS, 64 bit) it runs fine. However, on a VPS I have rented (same OS but no X11), while the application starts without problems, I get exceptions at runtime.

The call that causes the exception is the MeasureText method of class System.Windows.Forms.TextRenderer. In case you're wondering what this method is doing in a console app, it needs to measure the length of text rendered in a certain font for calculating the correct placements of text elements in SVG files it's creating. Exception message and stack trace excerpt below:

An exception was thrown by the type initializer for System.Windows.Forms.XplatUI


at System.Windows.Forms.TextRenderer.MeasureTextInternal (IDeviceContext dc, System.String text, System.Drawing.Font font, Size proposedSize, TextFormatFlags flags, Boolean useMeasureString) [0x00000] in <filename unknown>:0 
at System.Windows.Forms.TextRenderer.MeasureText (System.String text, System.Drawing.Font font) [0x00000] in <filename unknown>:0 

I think I have installed the font in question correctly on the server, at least it shows up when I call fc-list. So do I need X for this or are there ways around it? Am I just missing some package install on the server? Failing that, is there maybe an alternative that I could use to achieve the text measuring?

themik81
  • 401
  • 6
  • 17
  • You can run a dummy X11 server, it's probably the simplest workaround that doesn't make you change any code. – n. m. could be an AI Apr 27 '13 at 07:44
  • Thanks, I'm going to try that, found this SO post here, recommending xvfb, http://stackoverflow.com/questions/1337232/what-dummy-x-server-should-i-use-with-openoffice-on-debian. Will report back on how that went – themik81 Apr 29 '13 at 11:35

1 Answers1

0

I tried out the suggestion made above and it worked. I installed xvfb and am now running mono through xvfb-run. Exception has disappeared and memory usage on server hasn't gone up by much.

themik81
  • 401
  • 6
  • 17