abp9 .net8 升级错误记录

错误一、

Cannot find compilation library location for package 'System.Security.Cryptography.Pkcs'

修复方法: 将以下配置设置添加到您的 YX.OAM.Web.Mvc.csproj 文件中。

<GenerateRuntimeConfigDevFile>true</GenerateRuntimeConfigDevFile>

错误二、

使用多上下文,升级mysql Nuget包为8.0.1后,有时会导致无法访问另一个数据库的数据出现

Access denied for user 'root'@'10.244.4.1' (using password: NO)

通过查找资料需要更改链接字符串为

 "Default": "server=localhost;user=root;password=1234;database=ef";

错误三、

Token获取接口 http://localhost:5000/api/TokenAuth/Authenticate

报错: TIDX10720: Unable to create KeyedHashAlgorithm for algorithm 'HS256', the key size must be greater than: '256' bits, key has '176' bits. (Parameter 'keyBytes')
https://github.com/dotnet/aspnetcore/issues/49455

之前的密钥位数不够,密钥必需具有'256'位

"Authentication": {
  "JwtBearer": {
    "IsEnabled": "true",
    "SecurityKey": "XXXXX_o/YrU/xV2QRD4zLKMr0wNOvYARep4oF3ie+GPi5et6U=",//这里
    "Issuer": "XXXXX",
    "Audience": "XXXXX"
  },
  "Token": {
    "ExpiredTime": 30
  },
  "FunctionSwitch": {
    "FollowEnabled": true
  }
},

错误四、

运行项目时报错

2024-03-04 13:47:45,760 || FATAL || Abp.AbpBootstrapper || MySqlConnector.MySqlException (0x80004005): SSL Authentication Error
---> System.Security.Authentication.AuthenticationException: Cannot determine the frame size or a corrupted frame was received.

数据库来你姐字符串要增加 sslmode=None;

 "Default": "server=localhost;user=root;password=1234;sslmode=None;database=ef";

错误五、

因为解决方案中使用了盛派的包,需要将Senparc.Weixin.MP 到最新---16.20.5

在Startup.cs中需要修改

// 启动 CO2NET 全局注册,必须!
  app.UseSenparcGlobal(env, senparcSetting.Value, globalRegister => { })
      .UseSenparcWeixin(senparcWeixinSetting.Value, weixinRegister =>
      {
          weixinRegister.RegisterMpAccount(senparcWeixinSetting.Value, SenparcWeixinOptions.Name);
          weixinRegister.RegisterTraceLog(ConfigTraceLog);
      });
using Register = Senparc.CO2NET.Register;
// 启动 CO2NET 全局注册,必须!
var registerService = Register.UseSenparcGlobal(senparcSetting.Value, globalRegister => { })
     .UseSenparcWeixin(senparcWeixinSetting.Value, (weixinRegister, weixinSetting) =>
     {
         weixinRegister.RegisterMpAccount(senparcWeixinSetting.Value, SenparcWeixinOptions.Name);
         weixinRegister.RegisterTraceLog(ConfigTraceLog);
     });

错误六、

之前的项目时.net Core 3.1 数据库的一个类

public virtual byte[] RowVersion { get; set; }

Pomelo.EntityFrameworkCore.MySql version: 8.0.1
错误: in 8.0.1 Is Timestamp byte[] no longer supported

需要将其升级为8.0.0 或者8.0.2

错误七、

[MaxLength(2048)]
public virtual string Remarks{ get; set; }

报错: Data too long for column 'Remarks' at row 1

通过测试查看所有实体, 里面有约束MaxLength大于2000的, 全部删除掉即可

错误八、

.net8中, 使用了新的Host.CreateDefaultBuilder(args)创建服务, 因此, 需要对:Program 和Startup 进行修改:

Program

 using Abp.AspNetCore.Dependency;  
using Abp.Dependency;  
using Microsoft.AspNetCore.Hosting;  
using Microsoft.Extensions.Hosting;  
namespace XXXX.XXX.Web.Startup  
{  
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        internal static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            })
            .UseCastleWindsor(IocManager.Instance.IocContainer);
    }
}

Startup

ConfigureServices方法的返回值修改为void最后一行的return xxx修改为:

// Configure Abp and Dependency Injection  services.AddAbpWithoutCreatingServiceProvider<SCMWebMvcModule>(options => 
      options.IocManager.IocContainer.AddFacility<LoggingFacility>(  
      f => f.UseAbpLog4Net().WithConfig(_env.IsDevelopment()  
      ? "log4net.config"  
      : "log4net.Production.config"  
      )  
));

需要新增log4net.Production.config

 <?xml version="1.0" encoding="utf-8"?>

<log4net>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
        <file value="App_Data/Logs/Logs.log" />
        <appendToFile value="true" />
        <rollingStyle value="Size" />
        <maxSizeRollBackups value="10" />
        <maximumFileSize value="10000KB" />
        <staticLogFileName value="true" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date || %5level || %logger || %message || %exception ||end %newline" />
        </layout>
    </appender>
    <root>
        <appender-ref ref="RollingFileAppender" />
        <level value="DEBUG" />
    </root>
    <logger name="NHibernate">
        <level value="WARN" />
    </logger>
</log4net>