Mono and File Paths

The joy of developing cross platform applications!!

When dealing with files and paths on a windows based platform you always use a backslash () as the path separator, for example ‘ConfigSettings.xml’. Append the full path onto the beginning and you would be able to load the settings.  However, if your application needs to run on top Linux or Mac OS X (Mono) then file paths are slightly different. Instead of ‘ConfigSettings.xml’ you need to use ‘Config/Settings.xml’. Notice the all important forward slash (/)! It’s a simple mistake to make and it can take a few moments to realise what the problem is. 

If you wanted to be really hard core (and correct), you would use Path.DirectorySeparatorChar property to define your separator. Alternatively, you might want to look at IOMap which should solve this mismatch problem for you.

Variations like this is a great reason why you should run your unitintegration tests on both platforms as part of your build.

Technorati Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *