run in windows is ok, but centOS show error:Could not load file or assembly 'MySqlBackupNet.MySqlConnector, Version=2.3.6.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
CatcherX opened this issue · 4 comments
Could not load file or assembly 'MySqlBackupNet.MySqlConnector, Version=2.3.6.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
my code is :
backupPath += "\" + DateTime.Now.ToString("yyyy-MM-dd_HH_mm_ss.sql");
using (MySqlConnection conn = new MySqlConnection(GlobalContext.SystemConfig.DBConnectionString))
{
using (MySqlCommand cmd = new MySqlCommand())
{
using (MySqlBackup mb = new MySqlBackup(cmd))
{
cmd.Connection = conn;
conn.Open();
mb.ExportToFile(backupPath);
conn.Close();
}
}
}
MySqlBackupNet.MySqlConnector requires MySqlConnector.NET to run. You may download the .NET Core build of MySqlConnector.NET at: https://www.nuget.org/packages/MySqlConnector/
The idea is to build the project in .NET Core.
We can test this out with a simple Console App.
Starting by creating a .net core linux project:
Check the project properties, ensure the project is built with .NET Core framework:
Install Nuget Package of MySqlBackup.NET (with MySqlConnector):
Next, is to publish the project for .NET Core (Linux):
In above example, the Linux compiled binaries are located at:
\bin\Release\netcoreapp3.1\publish\linux-x64
Copy the DLL in above folder and paste it to your CentOS
At the CentOS, make sure that you have installed Dotnet runtime by following command:
sudo dnf install dotnet-sdk-<version>
For example:
sudo dnf install dotnet-sdk-3.1
sudo dnf install dotnet-sdk-5.0
Assume that you have copied your .NET Core DLL files at the following folder:
/home/<username>/testapp
Then you can test out your app with following command:
cd /home/admin/testapp
dotnet ConsoleApp.dll
Here is the sample source code for your referrence:
You can also compile the binaries into single "self-contained" binary. With this method, the .NET Core App can be run directly on CentOS (Linux) without installing any dotnet runtime.
Here is the screenshot for publishing the "self-contained" binary:
Here is the example of how it looks like after publishing, there is only 1 single file:
Copy the compiled binary to CentOS
At the terminal, browse to the folder that contains the self-contained binary, for example:
cd /home/admin/testapp
Next, is to allow execution permission to the file:
sudo chmod 777 ConsoleApp2
Execute the app:
./ConsoleApp2
MySqlBackupNet.MySqlConnector requires MySqlConnector.NET to run. You may download the .NET Core build of MySqlConnector.NET at: https://www.nuget.org/packages/MySqlConnector/
It's working fine now, thank you very much for your patient guidance @adriancs2