Bug 10953 - UI designer: images loaded from files are referenced in file gui.stetic (always) with OS dependent PathSeparator - built binaries crashs on different OS due to other PathSeparator
Summary: UI designer: images loaded from files are referenced in file gui.stetic (alwa...
Status: NEW
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: GTK# Designer ()
Version: 4.0.1
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2013-03-06 18:38 UTC by Markus Weber
Modified: 2013-03-06 18:40 UTC (History)
1 user (show)

Tags: file path separator stetic generated cross plattform windows linux slash backslash image
Is this bug a regression?: ---
Last known good build:

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 10953 on Developer Community or GitHub 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: Developer Community HTML or GitHub Markdown
  • 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 Markus Weber 2013-03-06 18:38:56 UTC

Using monodevelop 4.0.1 (same problem existed with 3.0.x too) on Windows 7:
Adding an image in the stetic UI designer to a widget, that loads an external picture from a subfolder will produce an entry like this in the gui.stetic called file:

<property name="Pixbuf">file:.\images\227px-Water_drop_on_a_leaf.jpg</property>

Be aware of the backslashes as Windows specific path separators.

The generated code file for this widget in the folder gtk-gui contains a code line like this:

		this.image10.Pixbuf = new global::Gdk.Pixbuf (global::System.IO.Path.Combine (global::System.AppDomain.CurrentDomain.BaseDirectory, ".\\images\\227px-Water_drop_on_a_leaf.jpg"));

If this project is compiled on Windows, transferred to a Linux machine and executed, it crashes, because it can not find the file at:


even if the file at 



(on Windows the executable runs without faults).

I guess the problem exists in the opposite direction too: designed and built in Linux, run in Windows.


Even if the images are placed in the same folder as the project file, the relative path contains ".\\".
Therefore I moved all pictures to the project file folder and removed the ".\\" manually from the lines in the file gui.stetic.

Solution Idea

In my opinion the relative paths in the file gui.stetic shall be written with an OS independent path separator (e. g. "/" like subversion), but the "\\" shall be supported too, that it is backward compatible to older source files.

No matter which OS is currently used (iOS, Windows, Linux, ...) the entry in gui.stetic is e. g.:
<property name="Pixbuf">file:./images/227px-Water_drop_on_a_leaf.jpg</property>

And instead of:
this.image10.Pixbuf = new global::Gdk.Pixbuf (global::System.IO.Path.Combine (global::System.AppDomain.CurrentDomain.BaseDirectory, ".\\images\\227px-Water_drop_on_a_leaf.jpg"));

Something like this shall be written in the generated code file (similar to icons):
this.image10.Pixbuf = global::Stetic.ImageLoader.LoadImage (this, global::System.AppDomain.CurrentDomain.BaseDirectory, "./images/227px-Water_drop_on_a_leaf.jpg");
(similar to Stetic.IconLoader.LoadIcon(...))

The new class ImageLoader and method LoadImage have to be implemented e. g. in the file "generated.cs".

I downloaded the source code and found the problem area (right?):

I am not sure, where the conversion has to be built in here and whether it's the right conversion direction:

             public static ImageInfo FromString (string str)
                    } else if (str.StartsWith ("file:")) {
                           info.source = ImageSource.File;
                           info.name = str.Substring (5).
                                       Replace(SteticPathSeparator, Path.PathSeparator). // default compatibility
                                       Replace(WindowsPathSeparator, Path.PathSeparator); // backward compatiblity gui.stetic with "\\" as path separators

             public CodeExpression ToCodeExpression (GeneratorContext ctx)
  case ImageSource.File: