obr*_*tim 3 .net c# typeinitializationexception .net-5 .net-core-publishsinglefile
如果使用单文件配置发布,应该将数据插入 MySql 数据库的简单控制台应用程序将失败:
dotnet publish -c Release -r linux-x64 -p:PublishSingleFile=true -o publish/ GarLoader.MySqlUploader
Run Code Online (Sandbox Code Playgroud)
如果我随后运行它 ( ./publish/GarLoader.MySqlUploader),它会失败。堆栈跟踪是:
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()
Run Code Online (Sandbox Code Playgroud)
如果它是在dotnet run没有发布的情况下启动的,它运行得很好。
是否有任何解决方法,以便我可以将其构建为单文件应用程序并运行?
简洁版本
使用MySqlConnector而不是 Oracle 的MySql.Data.
为什么
我怀疑您正在使用 Oracle 的 MySQL/Connector 驱动程序。该驱动程序有几个问题,使用System.Configuration.ConfigurationManager是其中较小的问题之一。
System.Configuration.ConfigurationManager是 .NET Framework 的一部分,而 .NET 5 实际上是 .NET Core 5。要使用它,您必须安装兼容性库,该库仅用于帮助迁移使用 .NET Framework 的应用程序app.config。Oracle 没有发布适当的 .NET Core 包,而是简单地使用兼容性库重新定位 .NET Framework 包。
更糟糕的问题是低效的异步支持和不频繁的发布,这意味着错误需要几个月甚至几年才能修复。
可以解决您当前问题的更好选择是使用MySqlConnector包。它不依赖于 .NET Core 中的兼容性包(实际上,它没有依赖项,句号)。
除此之外:
| 归档时间: |
|
| 查看次数: |
1057 次 |
| 最近记录: |