Problem
I am trying to conect MY SQL with my asp.net core 2.0 web application. But it throug me this error
Method 'Clone' in type 'MySql.Data.EntityFrameworkCore.Infraestructure.Internal.MySQLOptionsExtension' from assembly 'MySql.Data.EntityFrameworkCore, Version=6.10.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.
I am using Repository pattern in asp.net core 2.0 with EF 2.0
startup.cs
here the error occurs
services.AddDbContext<MyContext>(options =>
options.UseMySQL(
Configuration.GetConnectionString("DefaultConnection"),
b=>b.MigrationsAssembly("AspNetCoreMultipleProject")
));
It looks like this could be because the official MySQL provider doesn't work with EF core 2.0 - GitHub issue.
The suggested workaround is to use the Pomelo provider - MS documentation
Related
Apparently, with .Net Core 2.1, views are now supported. I was wondering if it is possible to scaffold a view using Pomelo, and if so, what the syntax is? I tried the "table" syntax with a view but it didnt work:
dotnet ef dbcontext scaffold "Server=myserver.com;Database=myDatabase;User=userame;Password=password;" "Pomelo.EntityFrameworkCore.MySql" -t personsView -o models
It runs, but it only generates a dbContext - it doesn't generate the model.
I'm using Pomelo 2.1.1 and Visual Studio 2017 (15.7.5). My project is a .Net Core 2.1 Web API. On the back end, I have MySQL Server 5.6.30.
Using Pomelo, you can use the following command (within the Package Manager Console) to generate the models as well as the context class:
Scaffold-DbContext [CONNECTION_STRING] Pomelo.EntityFrameworkCore.MySql -OutputDir [OUTPUT DIRECTORY] -Context [NAME OF CONTEXT CLASS] -f
Looking for help for some solutions on switching out the default data provider for the project from MS SQL to mySQL. Eventually with the intent of deploying the solution to Auruora on AWS.
After installing the nuget package I get something along the lines of :
System.TypeLoadException: Method 'Clone' in type 'MySql.Data.EntityFrameworkCore.Infraestructure.MySQLOptionsExtension' from assembly 'MySql.Data.EntityFrameworkCore, Version=6.10.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.
This lead me to believe that there is no .NET 2.0 Entity Framework Core extention that runs for MySQL. Do I have to rollback to a different version?
For EntityFrameworkCore, it's suggested to use Pomelo.EntityFrameworkCore.MySql.
You may refer to their Getting Started documentation.
A fellow member of the community has kindly summarised the essential steps here:
Put Pomelo.EntityFrameworkCore.MySql into the xxx.EntityFrameworkCore project's .csproj file (see step 2 in the Pomelo getting started guide)
In your xxxDbContextConfigurer class put builder.UseMySql(...) rather than builder.UseSqlServer(...)
Change the connection string found in the appsettings.json file in the xxx.Web.Host project
I have a weird problem here. I'm trying to access a MySql database with Entity Framework Core.
It works on the .NET console. but when the same code runs on the web app it says.
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0]
An unhandled exception has occurred while executing the request
System.TypeLoadException: Method 'Clone' in type 'MySQL.Data.EntityFrameworkCore.Infraestructure.Internal.MySQLOptionsExtension' from assembly 'MySql.Data.EntityFrameworkCore, Version=8.0.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.
at Microsoft.EntityFrameworkCore.MySQLDbContextOptionsExtensions.UseMySQL[TContext]
at ConsoleApplication.EmployeesContextFactory.Create(String connectionString) in BooksController.cs:line 65
Here is my code
var optionsBuilder = new DbContextOptionsBuilder<EmployeesContext>();
optionsBuilder.UseMySQL(connectionString);
var context = new EmployeesContext(optionsBuilder.Options);
context.Database.EnsureCreated();
It gives me the exception on the method UseMySql() The same exact code works fine in the console.
Also connectionString, .NET Core version and many of the constraints that I can think of are the same.
EDIT
Seeing the difference The ASP.NET project has following Nugets
The console app has the following,
Both projects show it's target framework as 2.0
What's the right way to solve this issue?
Because the current MySQL connector only supports .NET Core 1, you might not be able to use it with v2.
You could try this package at https://github.com/jasonsturges/mysql-dotnet-core
I'm using Dapper, .NET Core 2 and MySql.Data to create a small REST API on Linux. Unfortunately, i keep getting this error on my connection:
Exception has occurred: CLR/System.IO.FileNotFoundException
An exception of type 'System.IO.FileNotFoundException' occurred in MySql.Data.dll but was not handled in user code: 'Could not load file or assembly 'System.Security.Permissions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.'
at MySql.Data.MySqlClient.MySqlConnection.AssertPermissions()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at Dapper.SqlMapper.<QueryImpl>d__124`1.MoveNext()
Does anyone have any idea what is going on?
Try adding System.Security.Permissions, Version=4.0.0.0 from nuget.
I solved by upgrading to 8.0.8-dmr.
I don't know what's happening, but I get the same issue.
I have noticed that if you look at the DEPENDANCICES.NuGET node under the solution and look at the "MySqlData(6.9.9)" and expand it, you'll see a warning messages about something was restored with .net Framework 4.6.1. (in my case anyway)
It looks like to me, something in the NuGet package from the author isn't correct.
Yes, it seems is bug of MySql.Data.dll (My version is 6.10.6 from nugget-repository).
I'm trying to connect to Maria DB and get the same error:
Database not found on server with connection string in settings: Could not load file or assembly 'System.Security.Permissions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
error screenshot
I had solved that: There are 3 kinds of "MySql.Data.dll" lib at Nuget-package mysql.data 6.10.6.0:
netcoreapp 2.0 lib
netstandard 1.3 lib
netstandard 2.0 lib
During using netcoreapp 2.0 or netstandard 2.0 - it cames error.
During using netstandard 1.3 lib - it works finally, and has no error!
I am using MySQL with dotConnector from Devart. I'm trying to use the code-first with migrations that the library offers. It creates the migrations just fine, but when I try to call Update-Database in the package manager I'm getting this error
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Digging through my reference list, I'm using EntityFramework 5.0.0.0 and am targeting the v4.5 framework. Why would this be asking for v4.4 of EF?
I set up two connection strings, one using the regular MySQL provider, the other using dotConnector's MySQL provider, it didn't make a difference which one my context used. I've tried removing and re-adding the EF reference.
I'm so lost on this I don't even know what other information to give to help get a constructive answer. So, if there is more information I should give to help get a better answer, please let me know.
I've found more information about dotConnect and it looks like the Migrations portion targets 4.4. Does this mean I need to use EF 4.4? Or can I have both somehow so the migration has what it needs and I can use EF 5.0 everywhere else?
EF 4.4 is .NET 4.0 version of EF 5.0. It looks like something in your project is targeting .NET 4.0 (or is built for .NET 4.0).