So I'm trying to access a MySQL server in a UWP C# application, and whenever I try to compile I get the following error:
Severity Code Description Project File Line Suppression State
Error CS1705 Assembly 'MySql.Data' with identity 'MySql.Data, Version=8.0.28.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' uses 'System.Data.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Data.Common' with identity 'System.Data.Common, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' TestApp C:\Users\super\Documents\C#\TestApp\CSC 1 Active
Apparently this means that MySQL.Data.dll
is using a different version of the System.Data.Common
assembly?? I'm not sure what I need to do to rectify this, any help would be very much appreciated: :)
This is the file where I use the DLL:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
/// <summary>
/// The MySQLConnector namespace contains a class which will be used to provide a layer of
/// abstraction to connecting to a MySQL database. This will primarily be used for
/// retrieving data about a user.
/// </summary>
namespace MySQLConnector
{
/// <summary>
/// The DBConnection class is the class that will provide the aforementioned abstraction
/// </summary>
class DBConnection
{
private string connectionString; // String that will be used to connect to the DB
private MySqlConnection connection; // MySQLConnection object
/// <summary>
/// Constructor method, sets up the MySqlConnection object and the connection string
/// based on the supplied parameters.
/// </summary>
/// <param name="server">Hostname/IP address of the MySQL server</param>
/// <param name="db">Name of the database</param>
/// <param name="uid">Username to login with</param>
/// <param name="password">Password to login with</param>
public DBConnection(string server, string db, string uid, string password)
{
connectionString = $"SERVER={server};DATABASE={db};UID={uid};PASSWORD={password};";
connection = new MySqlConnection(connectionString);
}
/// <summary>
/// Attempts to open a connection to the MySql server.
/// </summary>
/// <returns>true: the connection was successful, false: the connection failed</returns>
private bool OpenConnection()
{
try
{
connection.Open();
return true;
}
catch (MySqlException ex)
{
return false;
}
}
/// <summary>
/// Attempt to close the connection to the MySql server
/// </summary>
/// <returns>true: Connection was closed successfully, false: the connection closure failed.</returns>
private bool CloseConnection()
{
try
{
connection.Close();
return true;
}
catch (MySqlException ex)
{
return false;
}
}
public User QueryUser(string username)
{
User result = null;
string query = $"SELECT * FROM users WHERE username like {username}";
if (this.OpenConnection())
{
MySqlCommand cmd = new MySqlCommand(query);
MySqlDataReader reader = (MySqlDataReader)cmd.ExecuteReader();
while (reader.Read())
{
result = new User();
result.id = reader["id"].ToString();
result.username = reader["username"].ToString();
result.password = reader["password"].ToString();
}
}
this.CloseConnection();
return result;
}
}
/// <summary>
/// User class, represents a user that has been retrieved from the database
/// </summary>
class User
{
public string id;
public string username;
public string password;
}
}
If you need any other information let me know:)
I've tried to use the MySql.Data.dll
file that is present in the other directories downloaded with the connector, but they don't seem to make much of a difference. I'm currently using: Assemblies.net6.0\MySql.Data.dll
, because I am using .NET 6.0.201.
So I switched to the Assemblies.netstandard2.0\MySql.Data.dll
dll, and installed the.netstandard 2.0 library through NuGet, and I now have different errors:
1>C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\XamlCompiler\Microsoft.Windows.UI.Xaml.Common.targets(584,5): error MSB3030: Could not copy the file "obj\x64\Debug\App.xbf" because it was not found.
1>C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\XamlCompiler\Microsoft.Windows.UI.Xaml.Common.targets(584,5): error MSB3030: Could not copy the file "obj\x64\Debug\MainPage.xbf" because it was not found.
1>C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\XamlCompiler\Microsoft.Windows.UI.Xaml.Common.targets(584,5): error MSB3030: Could not copy the file "obj\x64\Debug\\TestApp.xr.xml" because it was not found.
I checked the directory specified in the error message, and the files indeed do not exist, any ideas on what I can do here?
I managed to resolve the issue by removing manual references to MySql.Data.dll
, updating visual studio, adding MySql.Data.dll
through NuGet instead, and removed the System.Data.Common and.netstandard 2.0 packages I had installed through NuGet earlier, this allowed it to build, and from then I just had some SQL issues to fix before it worked fine:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.