c# - 版本丛林 MySQL.Data.xxxx.xxxx :

标签 c# mysql

我迷路了:我正在尝试让 MySQL 在我的一个小型控制台程序中工作; 我有一个在本地主机上运行的 MySQL 服务器,我可以通过 MySQL Workbench 8.0 CE 访问它。那里没问题。 我的程序在运行时出现以下异常:

Exception thrown: 'System.MethodAccessException' in MySql.Data.Entity.EF6.dll
Exception thrown: 'System.Data.Entity.Core.ProviderIncompatibleException' in EntityFramework.dll
Exception thrown: 'System.Data.Entity.Core.ProviderIncompatibleException' in EntityFramework.dll
Exception thrown: 'System.Data.Entity.Core.ProviderIncompatibleException' in mscorlib.dll
Exception thrown: 'System.MethodAccessException' in MySql.Data.Entity.EF6.dll
Exception thrown: 'System.Data.Entity.Core.ProviderIncompatibleException' in EntityFramework.dll
Exception thrown: 'System.Data.Entity.Core.ProviderIncompatibleException' in EntityFramework.dll

我在这里做错了什么?有人能在这个版本的丛林中发光吗?

这些是我所包含的引用资料的各个版本,取自“​​属性”屏幕:

EntityFramework.dll version 6.0.0.0
EntityFramework.SqlServer.dll version 6.0.0.0
MySQL.Data version 8.0.17.0
MySQL.Data.Entity.EF6 version 6.10.9.0
MySQL.Data.EntityFramework version 8.0.17.0

我使用的是 Windows 10 Pro 上的 .NET Framework 4.7.2,最新更新。

我的 app.config 看起来像:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
  </startup>
  <!-- You must un-comment the following element if you do not specify
  the connection string in program.cs -->
  <!--<connectionStrings>
    <add name="LicenseContext" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;Port=3306;Database=licenses;Uid=root;Pwd=-----" />
  </connectionStrings>-->
  <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <!--<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />-->
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices,MySql.Data.Entity.EF6,Version=6.10.9.0,Culture=neutral,PublicKeyToken=c5687fc88969c44d" />
    </providers>
  </entityFramework>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.17.0" newVersion="8.0.17.0" />        
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

这是程序的开始:

static void Main(string[] args)
{
    using (MySqlConnection conn = new MySqlConnection("Server=localhost;Port=3306;Database=licenses;Uid=root;Pwd=------"))
   // using (MySqlConnection conn = new MySqlConnection())
    {
        using (LicenseContext contextDB = new LicenseContext(conn, true))
        {
            contextDB.Database.CreateIfNotExists(); // <===== here
        }
        conn.Open();
        MySqlTransaction transaction = conn.BeginTransaction();
        try
        {

这是按照要求的packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.3.0" targetFramework="net472" />
  <package id="MySql.Data" version="6.10.9" targetFramework="net472" />
  <package id="MySql.Data.Entities" version="6.8.3.0" targetFramework="net472" />
  <package id="MySql.Data.Entity" version="6.10.9" targetFramework="net472" />
  <package id="System.Buffers" version="4.4.0" targetFramework="net472" />
  <package id="System.Memory" version="4.5.0" targetFramework="net472" />
  <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net472" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net472" />
  <package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net472" />
</packages>     

前 4 个异常开始出现在“CreateIfNotExists();”处线。 顺便说一句:当使用 .NET FW 4.72 时,这个“核心”看起来很可疑,不是吗?

最佳答案

首先,MySql.Data.Entity.EF6MySQL.Data.Entities 不是官方的 Oracle 软件包,并且非常旧。卸载它们并确保 app.config 中没有引用它们。

其次,MySql.Data.Entity 6.10.9 与 MySql.Data 8.0.17 不兼容。甲骨文renamed the packageMySql.Data.EntityFramework对于 v8.x。我建议将所有内容更新到 8.x 版本;您需要卸载MySql.Data.Entity并安装MySql.Data.EntityFramework

关于c# - 版本丛林 MySQL.Data.xxxx.xxxx :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58078204/

相关文章:

mysql - insert ignore .....select 正在锁定 select 内的表

c# - 如何在 Metro UI XAML 中声明空字符串

php - 这段 php 代码有什么问题,它不会插入数据?

mysql - 我的主键和外键是什么?

C# 应用程序 - 如何在 xaml 表单中显示网站?

python - 属性错误: 'tuple' object has no attribute 'encode' Arduino and MySQL

Mysql,类似主题

c# - 如何仅通过 userinfo 端点而不是访问 token 获取声明

c# - 在 C# (Visual Studio) 中将 WAV 文件转换为 FLAC

c# - 在 asp.net 图表中调整字体轴样式和大小?