首页 > 解决方案 > 仅使用 xamarin Andriod 连接到 mySQL 数据库时出现问题,但在 iOS 和 UWP 中有效

问题描述

我从 Xamarin 跨平台应用程序直接连接到 mySQL 服务器(仅用于学习目的)。该连接在 iOS 和 UWP 中运行良好,但在 android 中它会在此行中引发错误:await conn.OpenAsync();

这是完整的错误:

{System.TypeInitializationException:“MySql.Data.MySqlClient.MySqlConfiguration”的类型初始化程序引发了异常。---> System.Configuration.ConfigurationErrorsException:配置系统初始化失败---> System.PlatformNotSupportedException:此平台不支持操作。在 System.Configuration.ClientConfigPaths..ctor (System.String exePath, System.Boolean includeUserConfig) [0x00050] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0 在 System.Configuration.ClientConfigPaths.GetPaths (System.String exePath, System.Boolean includeUserConfig) [0x00018 ] 在 <0e721f564ffa49e6b1d97ad7b9fda1f2>:0 在 System.Configuration.ClientConfigurationHost.get_ConfigPaths () [0x0000a] 在 <0e721f564ffa49e6b1d97ad7b9fda1f2>:0 在 System.Configuration.ClientConfigurationHost.GetStreamName (System.

希望有人可以帮助我解决这个错误提前谢谢

标签: mysqlxamarin

解决方案


我使用的是 MySql.Data 包,显然它还不支持 Android

解决方法是:使用 MySqlConnector 包。

旁注:MySqlConnector 包不适用于:await conn.openAsync(); 我不得不使用: conn.open();

它适用于 iOS、Android 和 UWP。


推荐阅读