Base solution for your next web application
Open Closed

Using MySql in Abp sample project - failed #2108


User avatar
0
lcyhjx created

Today, I tried to using MySql in Abp sample project, but failed. I am guess the issue is caused by Abp.Zero.EntityFramework, can anyone know how to address it?

1 download sample project from ABP website 2 install MySql on windows, create a database named ‘sampledb’ <a class="postlink" href="https://dev.mysql.com/doc/refman/8.0/en/mysql-installer-gui.html">https://dev.mysql.com/doc/refman/8.0/en ... r-gui.html</a> <a class="postlink" href="https://downloads.mysql.com/archives/installer/">https://downloads.mysql.com/archives/installer/</a> 3 Install MySql.Data.Entity in EntityFramwwork and Web Project Install-Package MySql.Data.Entity -Version 6.9.9, it will install the dependency Mysql.Data also 4 Change web.config in Web Project <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6"> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> <providers> <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers> </entityFramework> <connectionStrings> <add name="Default" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;port=3306;database=sampledb;uid=root;password=*** " /> </connectionStrings>

<a class="postlink" href="http://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html">http://dev.mysql.com/doc/connector-net/ ... ork60.html</a> 5 Run Update-Database –Verbos in Package Manager Console, errors in the console. you can check the error message below. I am sure the MySql.Data is installed in EntityFramework and Web project. And also I can see it in packages folder.

system.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: Could not load file or assembly 'MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at MySql.Data.Entity.MySqlEFConfiguration..ctor() --- End of inner exception stack trace --- at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Data.Entity.Utilities.TypeExtensions.CreateInstance[T](Type type, Func2 exceptionFactory) at System.Data.Entity.Utilities.TypeExtensions.CreateInstance[T](Type type, Func3 typeMessageFactory, Func2 exceptionFactory) at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.<.ctor>b__1() at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue() at System.Lazy1.get_Value() at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.GetConfiguration() at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model) at System.Data.Entity.DbContext..ctor(String nameOrConnectionString) at Abp.Zero.EntityFramework.AbpZeroDbContext`3..ctor(String nameOrConnectionString) in D:\Halil\Github\module-zero\src\Abp.Zero.EntityFramework\Zero\EntityFramework\AbpZeroDbContext.cs:line 72 at HL.TSE.EntityFramework.TSEDbContext..ctor() in C:\E\MyPrograme\DoNet\HL.TSE\HL.TSE.EntityFramework\EntityFramework\TSEDbContext.cs:line 22 --- End of stack trace from previous location where exception was thrown ---

I am guess the issue is caused by Abp.Zero.EntityFramework, can anyone know how to address it?


2 Answer(s)
  • User Avatar
    0
    lcyhjx created

    I have addressed the issue. The root cause is using a incorrect version of MySql.Data.Entity. the latest stable version of MySql.Data.Entity is 6.9.9, so before I use it. But since the abp sample project is using .net framework 4.5.2, so need to use the version 6.8.3 of MySql.Data.Entity. Now it works fine for me.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks for sharing your solution :)