Simple console application, that should insert data to MySql database fails if published with single-file configuration:
dotnet publish -c Release -r linux-x64 -p:PublishSingleFile=true -o publish/ GarLoader.MySqlUploader
If I then run it (./publish/GarLoader.MySqlUploader), it fails. The stack trace is:
System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.
---> System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.MySqlConfiguration' threw an exception.
---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize
---> System.NotSupportedException: CodeBase is not supported on assemblies loaded from a single-file bundle.
at System.Reflection.RuntimeAssembly.get_CodeBase()
at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
at System.Configuration.ClientConfigurationHost.get_ConfigPaths()
at System.Configuration.ClientConfigurationHost.GetStreamName(String configPath)
at System.Configuration.ClientConfigurationHost.get_IsAppConfigHttp()
at System.Configuration.Internal.DelegatingConfigHost.get_IsAppConfigHttp()
at System.Configuration.ClientConfigurationSystem..ctor()
at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
--- End of inner exception stack trace ---
at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
at System.Configuration.ConfigurationManager.PrepareConfigSystem()
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at MySql.Data.MySqlClient.MySqlConfiguration..cctor()
--- End of inner exception stack trace ---
at MySql.Data.MySqlClient.MySqlConfiguration.get_Settings()
at MySql.Data.MySqlClient.Replication.ReplicationManager..cctor()
--- End of inner exception stack trace ---
at MySql.Data.MySqlClient.Replication.ReplicationManager.IsReplicationGroup(String groupName)
at MySql.Data.MySqlClient.MySqlConnection.Open()
at SqlWorker.ASqlWorker`1.Exec(String command, DbParametersConstructor parameters, Nullable`1 timeout, CommandType commandType, IDbTransaction transaction)
at GarLoader.MySqlUploader.Inserter`1.InsertAddressObjectTypes(String connectionString, IEnumerable`1 items)
at GarLoader.MySqlUploader.Inserter`1.InsertItems(String connectionString, IEnumerable`1 items)
at GarLoader.MySqlUploader.UploaderToMySql.InsertAddressObjectItems[T](IEnumerable`1 items)
at GarLoader.Engine.Updater.LoadGlobalEntry[T](ZipArchive arch, String entryBeginingSubname, Func`2 prepareItem)
at GarLoader.Engine.Updater.Update(DownloadFileInfo downloadFileInfo)
at GarLoader.Engine.Updater.Update()
It runs fine if it is launched by dotnet run without publishing.
Is there any workaround so I could build it as single-file application and run ?
System.Configuration.ConfigurationManageris a .NET Framework (aka .NET Old) class. You may need to use a newer client version or use a completely different client. Oracle's MySQL/Connector is ... idiosyncratic shall we say. After all, Oracle has no reason to make .NET's life easier. MySqlConnector may be a better alternative. It's used by the most popular EF provider for MySQL