monoapp-configdevartdotconnect

Does App.config (or ApplicationName.exe.config) work in mono?


I'm trying to get EntityFramework 6 with dotConnect for Oracle working on Mono. I have also all app configuration defined in userSettings section.

First thing I noticed is that my app has always default configuration, then I tried to make Devart.Data.Oracle provider working, but I got an error:

System.Configuration.ConfigurationErrorsException: Failed to find or load the registered .Net Framework Data Provider 'Devart.Data.Oracle'.

I checked my app with strace and using MONO_LOG_LEVEL:

MONO_LOG_LEVEL=debug mono Host.exe | grep config

And config file is loaded (successfully) couple of times during app startup.

I found few bug reports about configuration in mono, but they are quite old and I don't know if still actual.

https://bugzilla.xamarin.com/buglist.cgi?quicksearch=ApplicationSettingsBase+

Could you give me a hint how to get rid of provider section in App.config? I've managed to move almost all configuration to code (except of providers).


Solution

  • First, your exception is not about wrong configuration. It loaded and read your configuration, but then it cannot find provider (Devart.Data.Oracle) specified in that configuration. Most obvious reason for that is missing dll which contains that provider.

    Second, this is how I use EF6 + Devart's postgresql provider (you use Oracle, but that should be similar) on mono without any configuration files:

    public class PgSqlConfiguration : System.Data.Entity.DbConfiguration
    {
        public PgSqlConfiguration()
        {
            SetProviderServices("Devart.Data.PostgreSql", PgSqlEntityProviderServices.Instance);
            SetProviderFactory("Devart.Data.PostgreSql", PgSqlProviderFactory.Instance);
        }
    }
    

    Then mark your context with DbConfigurationType attribute like this:

    [DbConfigurationType(typeof(PgSqlConfiguration))]
    public partial class YourContext : DbContext {}
    

    Just replace PostgreSql providers with Oracle in code above (and don't forget to add missing dll if that is the case) and you should be fine.