inversionhourglass / Rougamo

Compile-time AOP component. Works with any method, whether it is async or sync, instance or static. Uses an aspectj-like pattern to match methods.
MIT License
393 stars 47 forks source link

肉夹馍3.0.1,blazor泛型抽象组件应用自定义拦截器报错。 #73

Closed bxjg1987 closed 3 months ago

bxjg1987 commented 3 months ago

哈哈,还是我! 这次问题应该与之前的无关。

我有个抽象的blazor泛型组件(编译后就是个类) blazor组件有几个生命周期方法,我在这些方法上应用了自定义的MoAttribute做拦截,处理全局异常。 但执行时,报错。

GenericArguments[0], 'TEntityDto', on 'BXJG.Utils.RCL.Components.TreeListBaseComponent`2[TEntityDto,TGetAllInput]' violates the constraint of type parameter 'TEntityDto'.
         at ZLJ.RCL.Components.TreeListBaseComponent`2.$Rougamo_SetParametersAsync(ParameterView parameters)
         at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
         at ZLJ.RCL.Components.TreeListBaseComponent`2.$Rougamo_SetParametersAsync(ParameterView parameters)
         at ZLJ.RCL.Components.TreeListBaseComponent`2.SetParametersAsync(ParameterView parameters) in D:\abp\src\ZLJ.RCL\Components\TreeListBaseComponent.cs:line 176

我生成程序后,反编译看了下,唯一觉得不对如下: 假如被拦截的方法为:overrde xxx() 拦截后自动生成的方法大致为: override $rougamo_xxx(); 肉夹馍生成的方法按理说不应该override,我也不是很确定这个问题。

复现步骤:

  1. 直接下载发行版:https://gitee.com/bxjg1987_admin/abp/releases/tag/0.0.4 或者克隆项目
  2. 使用VS2022打开ZLJ.sln
  3. 检查ZLJ.Migrator和ZLJ.WEB.Host中的数据库连接字符串
  4. 将ZLJ.Migrator设为启动项,启动开始迁移生成数据库,一路按y后回车,直到完成。
  5. 将ZLJ.WEB.Host设为启动项,ctrl + f5启动,这是后端api
  6. 将编译模式设置为release(否则肉夹馍全局异常拦截器会忽略)
  7. 将ZLJ.Web.BlazorAuto设为启动项,ctrl+f5 启动,这是前端页面
  8. 直接点击登录,进入首页
  9. 点击菜单【基础信息】>【数据字典】此时正常现实,因为使用的是肉夹馍2.x
  10. 关闭ZLJ.Web.BlazorAuto启动的黑框
  11. 修改ZLJ.RCL项目的csproj,将肉夹馍版本设置为3.0.1后,重新ctrl + f5启动ZLJ.Web.BlazorAuto
  12. 再次进入菜单【基础信息】>【数据字典】此时异常拦截器执行,提示错误。

看起来像是肉夹馍2.x和3.x对泛型的处理有区别。数据字典页面是继承抽象的泛型组件。

另外建议大佬可用在首页留个捐赠二维码,万一有人愿意请个咖啡啥的呢,O(∩_∩)O!

inversionhourglass commented 3 months ago

哈哈,感谢建议哈,不过作为并不流行的小众组件就先不搞了

你反编译产生的怀疑是有道理的,不论是否是这个原因,这个地方都是需要修改的

bxjg1987 commented 3 months ago

好的,理解,我先关闭这issue。不过这个应该跟组件无关,貌似针对泛型父类,以及泛型约束的处理,2.x与3.x有差别。感谢哈。

inversionhourglass commented 3 months ago

别关了,这个问题要解决的。3.0版本虽然在功能上看着没有太多更新,不过代码实现改动很大,可能存在一些之前没有的问题,感谢反馈

inversionhourglass commented 3 months ago

我知道了,你误解我意思了,我一开始回复的说的是捐赠二维码的事,类库太小众了,先不搞了,BUG的问题是发现了就一定会处理的

bxjg1987 commented 3 months ago

哈哈,我确实是看错了。

inversionhourglass commented 3 months ago

问题修复了,发了preview版本,正式版周一再发,感谢反馈

bxjg1987 commented 3 months ago

我安装了3.0.2 preview版本。测试了下,解决了部分问题。 blazor 有两种模式,server模式代码是在服务端执行的,webassembly模式,代码是编译为wasm下载到浏览器中执行的。 目前测试的结果是,webassembly模式问题已解决,但server模式中还是一样的问题,异常如下:

fail: ZLJ.RCL.Components.TreeListBaseComponent[0]
      GenericArguments[1], 'TGetAllInput', on 'BXJG.Utils.RCL.Components.TreeListBaseComponent`2[TEntityDto,TGetAllInput]' violates the constraint of type parameter 'TGetAllInput'.
         at ZLJ.RCL.Components.TreeListBaseComponent`2.$Rougamo_SetParametersAsync(ParameterView parameters)
         at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
         at ZLJ.RCL.Components.TreeListBaseComponent`2.$Rougamo_SetParametersAsync(ParameterView parameters)
         at ZLJ.RCL.Components.TreeListBaseComponent`2.SetParametersAsync(ParameterView parameters) in D:\abp\src\ZLJ.RCL\Components\TreeListBaseComponent.cs:line 176

如果需要测试,需要拉去最新代码(发行版未发布), 默认就是server模式,访问任何页面都会报错。 可以在ZLJ.Web.BlazorAuto\Components\App.razor.cs中切换 server或webassembly模式

 return new InteractiveServerRenderMode(false);  //server模式
 // return new InteractiveWebAssemblyRenderMode(false);  //webassembly模式
inversionhourglass commented 3 months ago

啊,还有高手

inversionhourglass commented 3 months ago

已发布新的预发版本,有空了可以再试试,感谢多次反馈,我自己写的单元测试还是远远无法覆盖众多的代码规则,还是得靠你们的反馈来慢慢补齐

bxjg1987 commented 3 months ago

测试了,这次是真的两种模式都可以了。大佬辛苦啦!!!太感谢了。。