Bug #113311 Scaffold-dbContext is throwing Could not load type 'MySql.Data.MySqlClient.MySql
Submitted: 1 Dec 2023 19:45 Modified: 6 Dec 2023 12:53
Reporter: ed mcfadden Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.2.0 OS:Windows (Visual Studio)
Assigned to: CPU Architecture:Any
Tags: EntityFramework EF, Scaffold-Dbcontext

[1 Dec 2023 19:45] ed mcfadden
Description:
I am getting the following error when trying to scaffold a new data model from an existing database: 

The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Project 'MySqlConsoleTests' is not found.
PM> Scaffold-DbContext "server=localhost,Port=3306;Database=OperaCloudSupport;Uid=root;Pwd=whatdoyouneed;" MySql.EntityFrameworkCore -o models -t StayMessages  -f 
Build started...
Build succeeded.
System.TypeLoadException: Could not load type 'MySql.Data.MySqlClient.MySqlGuidFormat' from assembly 'MySql.Data, Version=8.0.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.
   at MySql.EntityFrameworkCore.Extensions.MySQLServiceCollectionExtensions.AddEntityFrameworkMySQL(IServiceCollection services)
   at MySql.EntityFrameworkCore.Design.Internal.MySQLDesignTimeServices.ConfigureDesignTimeServices(IServiceCollection serviceCollection)
   at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureDesignTimeServices(Type designTimeServicesType, IServiceCollection services)
   at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureProviderServices(String provider, IServiceCollection services, Boolean throwOnError)
   at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.CreateServiceCollection(String provider)
   at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Could not load type 'MySql.Data.MySqlClient.MySqlGuidFormat' from assembly 'MySql.Data, Version=8.0.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.

How to repeat:
I created a new project in Visual Studio to run the example found on https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework-core-scaffold-exa... but using the MySql.EntityFrameworkCore 8.0.0-previews and Microsoft.EntityFrameworkCore.Tools 8.0.0 from Nuget

I ran this command in the PM. 

Scaffold-DbContext "server=localhost,Port=3306;Database=OperaCloudSupport;Uid=root;Pwd=*****;" MySql.EntityFrameworkCore -o models -t StayMessages  -f

The project was a simple console application.
[1 Dec 2023 19:48] ed mcfadden
I am using visual studio
Microsoft Visual Studio Professional 2022
Version 17.8.2
VisualStudio.17.Release/17.8.2+34322.80
Microsoft .NET Framework
Version 4.8.09032

Installed Version: Professional

Visual C++ 2022   00476-80000-00000-AA709
Microsoft Visual C++ 2022

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools   17.8.358.6298
ASP.NET and Web Tools

Azure App Service Tools v3.0.0   17.8.358.6298
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio   2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   17.8.358.6298
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter   17.0.23262.1
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Extensibility Message Bus   1.4.39 (main@e8108eb)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

JSON Schema Tools   1.0.11
Allows you to easily generate a schema file from a JSON file and generate a JSON file with dummy data based on a schema file.

Linux Core Dump Debugging   1.0.9.34309
Enables debugging of Linux core dumps.

Microsoft Azure Hive Query Language Service   2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service   2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio   2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio   17.8.17 (957fbed)
Support for debugging Mono processes with Visual Studio.

Node.js Tools   1.5.50908.1 Commit Hash:c294679b821c4b8f7f9c6db3827b7655db80fc28
Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager   6.8.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Office Developer Tools for Visual Studio   17.6.34024.01
Microsoft Office Developer Tools for Visual Studio

Python - Profiling support   17.0.23262.1
Profiling support for Python projects.

Python with Pylance   17.0.23262.1
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Razor (ASP.NET Core)   17.8.3.2353105+f0a326f3e15b2370371693a76fd379635387c74d
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools   17.8.119.0
Microsoft SQL Server Data Tools

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   17.0.20920.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Linux Development   1.0.9.34309
Visual C++ for Linux Development

Visual F# Tools   17.8.0-beta.23475.2+10f956e631a1efc0f7f5e49c626c494cd32b1f50
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   17.8.0.155 (d17-8@7042beb)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   17.8.3.6 (remotes/origin/d17-8@eccf46a291)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK   13.2.2.0 (d17-5/45b0e14)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: d9a6e87
    Java.Interop: xamarin/java.interop/d17-5@149d70fe
    SQLite: xamarin/sqlite/3.40.1@68c69d8
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d
[2 Dec 2023 15:26] Bradley Grainger
It looks like the dependencies for https://www.nuget.org/packages/MySql.EntityFrameworkCore/8.0.0-preview#dependencies-body-t... are wrong.

It might start working if you explicitly installed MySql.Data 8.2.0 into your project.
[4 Dec 2023 16:00] ed mcfadden
Added MySQL.Data 8.2.0 and came up with a new error: 

 
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Diagnostics.IDiagnosticsLogger`1[Microsoft.EntityFrameworkCore.DbLoggerCategory+Scaffolding]' while attempting to activate 'MySql.Data.EntityFrameworkCore.Scaffolding.Internal.MySQLDatabaseModelFactory'.

Then I added and updated the packages....   

<PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>net8.0</TargetFramework>
  <ImplicitUsings>enable</ImplicitUsings>
  <Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0" />
  <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
  </PackageReference>
  <PackageReference Include="Microsoft.IdentityModel.Logging" Version="7.0.3" />
  <PackageReference Include="MySql.Data" Version="8.2.0" />
  <PackageReference Include="MySql.EntityFrameworkCore" Version="8.0.0-preview" />
</ItemGroup>

and received this error...

Method not found: 'Void CoreTypeMappingParameters..ctor(System.Type, Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter, Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer, Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer, Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer, System.Func`3<Microsoft.EntityFrameworkCore.Metadata.IProperty,Microsoft.EntityFrameworkCore.Metadata.IEntityType,Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator>)'.

Thanks for your assistance.
[6 Dec 2023 12:53] MySQL Verification Team
Hello!

Thank you for the bug report.
Verified as described.

Regards,
Ashwini Patil