My Razor Pages project is experimental one. It is targeted on working with MySQL database for Visual Studio. Initially, I built the project on ASP .NET Core 2.2 and successfully upgraded to ASP.Net Core 3.1. Now I’m trying to migrate the project to ASP .NET Core 5.0.
After updating the project as recommended in Migrate from ASP.NET Core 3.1 to 5.0, I have encountered the following error in “Startup.cs” file:Fig.1
The next image depicts the error code:Fig 2
Installed packages list:Fig 3
I tried to do some things to fix the error:Fig.4
In the figure 4, you can see that I’m going to add a parameter. I added the one, which I set to “null”. The error eliminated but the problem remained. After successful project compilation, I started the project, but received the following error:Fig. 5
In the figure 5, you can see that the source of the error is “Pamelo.EntityFrameworkCore.MySql” and the message is “The Server Version has not been set”. However, why it has not been auto detected? Well, if the second parameter is not to be set to “null”, then how this parameter is to be set?
To answer this question really helped me the following article:Pomelo.EntityFrameworkCore.MySql
Now the “error” line works well and looks as follows
services.AddDbContext<ApplicationContext>(options => options.UseMySql(
connection,
new MySqlServerVersion(new Version(5, 7, 17))
));
The project works well, but questions remain. What can I do if I can’t find server version? Why auto detect does not work as in the earlier package version for ASP .NET Core 3.1? Why should I depend on the server version?
Returning to the figures 1 – 3, I have the question:
Should I expect that the original code (auto detect) would work after Pamelo.EntityFrameworkCore.MySql (v 5.0.0) package release version will be published?
Any help would be appreciated.