From dfac28f54afc67f77e306e31d1277ffdffc4d306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=8D=E9=94=90?= <1565842059@qq.com> Date: Fri, 31 Jul 2026 10:49:18 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"fix(sac):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E9=A1=B5=E5=BA=8F=E5=88=97=E5=8C=96=20SacInf?= =?UTF-8?q?o=20=E6=97=B6=20TypeId=20=E8=A7=A6=E5=8F=91=20IsGenericParamete?= =?UTF-8?q?r=20=E5=BC=82=E5=B8=B8"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit ca74095e0c26d9fba9a5cb6a40811ebaa5ec11f3. --- .../SAC/Common/Sac_TranslateHelper.cs | 6 ------ YLErpWeb/App/ExceptionMiddleware.cs | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/YLErpDAL/Modules/SuperviseReportModule/SAC/Common/Sac_TranslateHelper.cs b/YLErpDAL/Modules/SuperviseReportModule/SAC/Common/Sac_TranslateHelper.cs index 4a2bc9a5..822f4c2e 100644 --- a/YLErpDAL/Modules/SuperviseReportModule/SAC/Common/Sac_TranslateHelper.cs +++ b/YLErpDAL/Modules/SuperviseReportModule/SAC/Common/Sac_TranslateHelper.cs @@ -117,12 +117,6 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Common [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)] public class SacDescriptionAttribute : Attribute { - // Attribute.TypeId 本质是 System.Type,Newtonsoft 序列化会触发 - // "Method may only be called on a Type for which Type.IsGenericParameter is true." - // 预览页用 ToJson() 序列化 SacInfo/List 时崩溃,故显式跳过该成员。 - // (13.0.1 安全版对 Type 成员序列化行为变更后暴露此问题) - public bool ShouldSerializeTypeId() => false; - /// /// 字段名 /// diff --git a/YLErpWeb/App/ExceptionMiddleware.cs b/YLErpWeb/App/ExceptionMiddleware.cs index 5163baaa..a0c469d2 100644 --- a/YLErpWeb/App/ExceptionMiddleware.cs +++ b/YLErpWeb/App/ExceptionMiddleware.cs @@ -37,15 +37,13 @@ namespace YLErp.Web.App try { - // 暴露完整异常(类型 + 所有内层 message + 堆栈),不再只取最内层 message, - // 便于定位根因(如 SacInfo 序列化 TypeId 触发的 IsGenericParameter 反射异常)。 - message = exception.ToString(); + message = GetInnerExceptionMessage(exception); if (serviceExpcetion == null || serviceExpcetion.IsFaultError) { var result = await request.BodyReader.ReadAsync(); var reqBody = ConvertBufferToString(result.Buffer); - LogFactory.GetLogger(context.Request.Path.Value).Error(serviceExpcetion ?? exception, $"[query]:{request.QueryString.Value};[body]:{reqBody}\r\n{message}"); + LogFactory.GetLogger(context.Request.Path.Value).Error(serviceExpcetion ?? exception, $"[query]:{request.QueryString.Value};[body]:{reqBody}"); } } catch (Exception ex) @@ -79,5 +77,16 @@ namespace YLErp.Web.App ReadOnlySpan span = readOnlySequence.IsSingleSegment ? readOnlySequence.First.Span : readOnlySequence.ToArray().AsSpan(); return System.Text.Encoding.UTF8.GetString(span); } + + private static string GetInnerExceptionMessage(Exception ex) + { + var exceptionStr = ex.Message; + while (ex.InnerException != null) + { + exceptionStr = ex.InnerException.Message; + ex = ex.InnerException; + } + return exceptionStr; + } } } \ No newline at end of file