1

I am trying to my .NET Framework web application to work with entity framework and a MySQL database

I followed the steps for enabling Entity Framework with MySql in this article: https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html

It all looked rainbow unicorn and sunshine until I tried to:

  1. Do an Add-Migration after a enable-migrations in the Package Manager Console.
  2. Start the webapplication.

I use the following components:

  • .NET Framework 4.5.2
  • Entity Framework 6.2.0
  • MySql.Data.Entity 6.10.8
  • MySQL database 5.7

I get the following errors:

Add-Migration error:

System.NullReferenceException: Object reference not set to an instance of an object.
   at MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection connection)
   at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
   at MySql.Data.Entity.MySqlManifestTokenResolver.ResolveManifestToken(DbConnection connection)
   at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
   at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
   at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
   at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized()
   at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
   at System.Data.Entity.Utilities.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w)
   at System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action`1 writeXml)
   at System.Data.Entity.Utilities.DbContextExtensions.GetModel(DbContext context)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
   at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Object reference not set to an instance of an object.

Web application data access error:

Object reference not set to an instance of an object.
   at MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection connection)
   at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
   at MySql.Data.Entity.MySqlManifestTokenResolver.ResolveManifestToken(DbConnection connection)
   at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
   at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
   at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
   at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.InternalContext.Initialize()
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.Include(String path)
   at System.Data.Entity.Infrastructure.DbQuery`1.Include(String path)
   at System.Data.Entity.QueryableExtensions.Include[T](IQueryable`1 source, String path)
   at System.Data.Entity.QueryableExtensions.Include[T,TProperty](IQueryable`1 source, Expression`1 path)
   at Jotihunt.Data.DataAccess.MapData.GetCars() in C:\SourceControl\BitBucket\Jotihunt\Data.DataAccess\MapData.cs:line 117
   at Jotihunt.Business.Logic.CarFacade.GetAll() in C:\SourceControl\BitBucket\Jotihunt\Business.Logic\CarFacade.cs:line 30
   at Jotihunt.Presentation.Web.Api.CarController.Get() in C:\SourceControl\BitBucket\Jotihunt\Jotihunt.Presentation.Web\Api\CarController.cs:line 21
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
   at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)

I tried what is suggested in this question: Add-Migration not working with MySQL Unfortunatly that didn't work..

5
  • What version of the MySql.Data NuGet package are you using? Commented Oct 12, 2018 at 16:43
  • Thank you for your question. I created a new solution with only ONE project. In that project I am using MySql.Data.EntityFramework in stead of MySql.Data.Entity. This question has the DbContext in a different project than where the connectionstring is held. Because of this I don't get detailed exceptions. By only having one project, the exception showed me the exact problem. Commented Oct 15, 2018 at 12:22
  • Also dev.mysql.com/doc/connector-net/en/… is not up to date. It should cover the MySql.Data.EntityFramework instead of MySql.Data.Entity. Commented Oct 15, 2018 at 12:23
  • I covered the new package in my answer here: stackoverflow.com/a/50222387. Since Oracle maintains that documentation site, you could report a documentation bug at bugs.mysql.com. Commented Oct 15, 2018 at 14:02
  • Possible duplicate of Error-Attempt by method 'X.set_DbConnection(System.Data.Common.DbConnection)' to access method 'Y.get_Settings()' failed Commented Oct 15, 2018 at 15:01

1 Answer 1

1

Make sure the following software have the same version:

MySQL Connector/NET
MySql.Data/MySql.Data.Entity/MySql.Data.EntityFrameworks

maybe this could be helpful when someone google this thread as I was.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.