Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Monodevelop support configuration files?

I added a file app.config to a C# mono project.

Inside the project I used

foreach (string key in ConfigurationManager.AppSettings)
{
string value = ConfigurationManager.AppSettings[key];
Console.WriteLine("Key: {0}, Value: {1}", key, value);
}

The config file looks like this

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Key1" value="Kevin" />
<add key="Key2" value="150" />
<add key="Key3" value="Rice" />
</appSettings>
</configuration>

No keys are detected. How can I read the config values?

like image 923
johnlemon Avatar asked Jun 22 '11 14:06

johnlemon


People also ask

Is MonoDevelop better than Visual Studio?

Monodevelop is less stable as compared to Visual studio. It is good when dealing with small projects. Visual Studio is more stable and has the ability to deal with all types of projects whether small or large. Monodevelop is a lightweight IDE, i.e. it can also run on any system even with fewer configurations.

What happened to MonoDevelop?

Visual Studio for Mac will replace MonoDevelop-Unity as the default C# IDE for using Unity on macOS, while Windows installations will continue to feature the free Visual Studio 2017 Community edition and will no longer include MonoDevelop-Unity as an alternative.

What is MonoDevelop used for?

MonoDevelop enables developers to quickly write desktop and web applications on Linux, Windows and macOS. It also makes it easy for developers to port . NET applications created with Visual Studio to Linux and macOS maintaining a single code base for all platforms.

What languages does MonoDevelop support?

MonoDevelop integrates a Gtk# GUI designer called Stetic. It supports Boo, C, C++, C#, CIL, D, F#, Java, Oxygene, Vala, JavaScript, TypeScript and Visual Basic.NET.


1 Answers

This answer comes awfully late, but for anybody that comes across this, yes, mono does support configuration files. You can use the ConfigurationManager method discussed above or you can even create your own custom settings section in the app.config file and manipulate it through a class which derives from ApplicationSettingsBase. In my opinion, this is a much more natural way of handling the app.config file because you work with a class and strongly typed properties, rather than accessing strings out of an array with the way that ConfigurationManager does it. Creating a class for app settings is pretty easy, too. Here's the MSDN page explaining how to create the class: http://msdn.microsoft.com/en-us/library/system.configuration.applicationsettingsbase.aspx

The only caveat to be aware of with Mono is that the .NET Framework allows UserScopedSettings to be defined in the app.config file (to provide a default value) but Mono will throw exceptions if you do that. The workaround for that is to leave UserScopedSettings out of the app.config file and just define the default value for a property in code. This isn't a perfect workaround because it doesn't give a way to change the default value outside of the code, but this will be sufficient in most cases.

like image 141
greyseal96 Avatar answered Sep 27 '22 19:09

greyseal96