You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 9升级后Pomelo.EntityFrameworkCore.MySql兼容性异常求助

问题描述

将18个月未维护的项目升级至.NET 9.0、Microsoft.EntityFrameworkCore 9.0.0正式版,并使用Pomelo.EntityFrameworkCore.MySql 9.0.0-preview.1(也尝试过夜间构建版本)后,抛出以下异常:

System.TypeLoadException: 'Method 'get_LockReleaseBehavior' in type 'Pomelo.EntityFrameworkCore.MySql.Migrations.Internal.MySqlHistoryRepository' from assembly 'Pomelo.EntityFrameworkCore.MySql, Version=9.0.0.0, Culture=neutral, PublicKeyToken=2cc498582444921b' does not have an implementation.'

已尝试同类问题的常规解决方案但无效,怀疑Pomelo与.NET 9正式版存在兼容性问题。项目.csproj配置如下:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DocumentationFile></DocumentationFile>
  </PropertyGroup>
  <ItemGroup>
    <Compile Remove="Luckins Data Entities\Original-LuckinsContext.cs" />
    <Compile Remove="Luckins Data Entities\supplierdetail.cs" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Coravel.Pro" Version="5.2.3" />
    <PackageReference Include="EfCore.SchemaCompare" Version="7.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="9.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="MySqlConnector" Version="2.4.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0-preview.1" />
    <PackageReference Include="PresentationFramework" Version="4.6.0" />
    <PackageReference Include="Serilog" Version="4.2.0" />
    <PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
    <PackageReference Include="Serilog.Sinks.MySQL" Version="5.0.0" />
    <PackageReference Include="SSH.NET" Version="2024.2.0" />
    <PackageReference Include="System.Linq.Dynamic.Core" Version="1.5.0" />
  </ItemGroup>
</Project>
解决办法
  • 版本对齐EF Core预览版:将所有Microsoft.EntityFrameworkCore相关包降级至与Pomelo预览版匹配的EF Core 9预览版本(如9.0.0-preview.7),因为EF Core 9正式版新增了LockReleaseBehavior API,当前Pomelo预览版未实现该接口成员。
  • 等待Pomelo正式版/更新夜间包:Pomelo的正式9.0.0版本会适配EF Core 9正式版,若需继续使用EF Core正式版,可尝试获取最新的Pomelo夜间构建包(确认其已针对EF Core 9正式版更新)。
  • 清理冗余数据库提供者包:项目中同时引用了Microsoft.EntityFrameworkCore.SqlServer和Pomelo.EntityFrameworkCore.MySql,若实际使用MySQL,建议移除SqlServer相关包,避免版本冲突和API混淆。
  • 清理NuGet缓存并重新还原:执行以下命令清理本地NuGet缓存,再重新还原依赖,避免缓存中旧版本文件干扰:
    dotnet nuget locals all --clear
    dotnet restore
    

内容的提问来源于stack exchange,提问作者Cliff Conway

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 17:24:51