title: Exception when accessing a MySQL database with Entity Framework
body: <p>I am trying to my .NET Framework web application to work with entity framework and a MySQL database</p>
  
  <p>I followed the steps for enabling Entity Framework with MySql in this article: <a href="https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html" rel="nofollow noreferrer">https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html</a></p>
  
  <p>It all looked rainbow unicorn and sunshine until I tried to:</p>
  
  <ol>
  <li>Do an <code>Add-Migration</code> after a <code>enable-migrations</code> in the Package
  Manager Console.</li>
  <li>Start the webapplication.</li>
  </ol>
  
  <p>I use the following components:</p>
  
  <ul>
  <li><code>.NET Framework 4.5.2</code></li>
  <li><code>Entity Framework 6.2.0</code></li>
  <li><code>MySql.Data.Entity 6.10.8</code></li>
  <li><code>MySQL database 5.7</code></li>
  </ul>
  
  <p>I get the following errors:</p>
  
  <p>Add-Migration error:</p>
  
  <pre><code>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&amp; 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.&lt;&gt;c__DisplayClass1.&lt;GetModel&gt;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.
  </code></pre>
  
  <p>Web application data access error:</p>
  
  <pre><code>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&amp; 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.&lt;&gt;c__DisplayClass13.&lt;GetExecutor&gt;b__c(Object instance, Object[] methodParameters)
     at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
     at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.&lt;&gt;c__DisplayClass5.&lt;ExecuteAsync&gt;b__4()
     at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
  </code></pre>
  
  <p>I tried what is suggested in this question: <a href="https://stackoverflow.com/questions/50132036/add-migration-not-working-with-mysql">Add-Migration not working with MySQL</a>
  Unfortunatly that didn't work..</p>