Registry settings in mono on Linux

Obviously, Linux does not have a registry. However, just like the .NET framework, Mono provides the Microsoft.Win32.Registry class for accessing the registry. So how does it work on Linux?

First, I would like to state that personally, I never use the registry. I hate using it for lots of reasons. But I do have situations where third party frameworks use the registry, and I use these framework on Mono/Linux, and hence I become dependent of it.

System wide settings

The system wide settings which are shared between users, e.g. HKCR, are stored in /etc/mono/registry. E.g. in /etc/mono/registry/ClassesRoot/. In this sub directory sub keys are stored as sub folders, and values are stored in xml files with the name values.xml:

<values>
<value name="Content Type"
type="string">application/msword</value>
</values>

This example is from /etc/mono/registry/ClassesRoot/.doc/values.xml.

User settings (e.g. HKCU) are stored in the same way, but in the sub folder  .mono/registry to the users home directory instead, e.g. ~/.mono/registry/CurrentUser.

Finally, if you are running a web app, please remember to ensure correct security settings if the web app should have access to specific or all registry settings. For example:

chmod 777 /etc/mono/registry/ClassesRoot -R

This will allow read and write access to ClassesRoot and all sub folders. Often you can loosen up on Linux registry settings security compared to Windows, but please remember to be careful.

4 responses to “Registry settings in mono on Linux

  1. You sir, have created a great deal of work for me, but have saved me days of frustration. I haven’t been able to determine whether registry settings persist or where they live under Mono. You have answered both. Thanks!

  2. I had a chance to check this out when I got home and noticed that I didn’t have a “/etc/mono” directory. I’ve installed both Mono Runtime and SDK, but still no folder.

    Is there any setup required to get the registry working on Mono? I’m pulling down the source right now so I can look through the specific implementation. Thanks.

  3. Hi, I’m no Linux wizard, but two suggestions to find the relevant path in your linux environment:

    1. run: sudo find / -name ‘mono’, OR
    2. programmatically set the registry values, and find out where they went:
    2a. Create a file with the name “setRegistry.cs” and the content in this link: https://gist.github.com/1409233 (or similar content relevant to you).
    2b. run: gmcs setRegistry.cs. This build setRegistry.exe.
    2c. run: mono setRegistry.exe. The registry folder is programatically created.
    2d. run: find / -name ‘values.xml’ or locate the folder in some other way.

    Br. Morten

  4. Update: I just discovered that an environment variable exists: $MONO_REGISTRY_PATH. This enables you to control where the system wide registry settings are stored. You can set it like this:

    export MONO_REGISTRY_PATH=/etc/test

    (or what ever suits you)

    Test it with: echo $MONO_REGISTRY_PATH

    Remember to store this in your startup script, so you do not loose the changes during reboot.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s