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在blazor web app 项目确实有问题 #71

Closed bxjg1987 closed 3 months ago

bxjg1987 commented 3 months ago

参考: https://learn.microsoft.com/zh-cn/dotnet/core/compatibility/serialization/8.0/publishtrimmed

发布时报错如下: 严重性 代码 说明 项目 文件 行 禁止显示状态 错误 优化程序集的大小失败。通过将 PublishTrimmed 属性设置为 false 可禁用优化。 ZLJ.Web.BlazorAuto 0

inversionhourglass commented 3 months ago

正如我在 #69 中回复的那样,我对blazor并不熟悉,方便的话提供一个简易的可复现问题的blazor项目,并简单说明复现步骤

bxjg1987 commented 3 months ago

好的,晚点我上传一份

bxjg1987 commented 3 months ago

测试了,空的blazor项目,rougamo3.0完全没问题,是我项目估计哪里冲突了。非常抱歉哈!

inversionhourglass commented 3 months ago

没事,你可以看看你报错的项目是不是编译打包有特殊设置。后面如果能复现问题,直接reopen这个issue,不用新建

bxjg1987 commented 3 months ago

感谢哈!我昨天一直在测试, 新建blazor web app 8.0 会创建两个项目(其中client项目仅用于浏览器中运行),在client项目中引用肉夹馍3.0,发布一切正常。 疑惑的是我的项目,2.x的肉夹馍,没有问题,引用肉夹馍3,发布过程有部分会编译为webassembly的wasm文件时出错了。 内容如下:

ILLink(0,0): 错误 IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink
Fatal error in IL Linker
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'instruction')
   at Mono.Cecil.Cil.InstructionOffset..ctor(Instruction instruction)
   at Mono.Cecil.Cil.CodeReader.ReadAsyncMethodBody(AsyncMethodBodyDebugInformation async_method)
   at Mono.Cecil.Cil.CodeReader.ReadCustomDebugInformations(MethodDefinition method)
   at Mono.Cecil.Cil.CodeReader.ReadDebugInfo()
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody()
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.MetadataReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.MethodDefinition.<>c.<get_Body>b__41_0(MethodDefinition method, MetadataReader reader)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Mono.Cecil.MethodDefinition.get_Body()
   at Mono.Linker.Dataflow.CompilerGeneratedState.<GetCompilerGeneratedStateForType>g__ProcessMethod|11_0(MethodDefinition method, <>c__DisplayClass11_0&)
   at Mono.Linker.Dataflow.CompilerGeneratedState.GetCompilerGeneratedStateForType(TypeDefinition type)
   at Mono.Linker.Dataflow.CompilerGeneratedState.GetGeneratedTypeAttributes(TypeDefinition generatedType)
   at ILLink.Shared.TrimAnalysis.FlowAnnotations.GetGeneratedTypeAttributes(TypeDefinition typeDef)
   at ILLink.Shared.TrimAnalysis.FlowAnnotations.BuildTypeAnnotations(TypeDefinition type)
   at ILLink.Shared.TrimAnalysis.FlowAnnotations.GetAnnotations(TypeDefinition type)
   at ILLink.Shared.TrimAnalysis.FlowAnnotations.GetTypeAnnotation(TypeDefinition type)
   at Mono.Linker.Dataflow.DynamicallyAccessedMembersTypeHierarchy.ProcessMarkedTypeForDynamicallyAccessedMembersHierarchy(TypeDefinition type)
   at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, Nullable`1 origin)
   at Mono.Linker.Steps.MarkStep.MarkField(FieldDefinition field, DependencyInfo& reason, MessageOrigin& origin)
   at Mono.Linker.Steps.MarkStep.MarkEntireType(TypeDefinition type, DependencyInfo& reason)
   at Mono.Linker.Steps.MarkStep.MarkEntireType(TypeDefinition type, DependencyInfo& reason)
   at Mono.Linker.Steps.MarkStep.MarkEntireAssembly(AssemblyDefinition assembly)
   at Mono.Linker.Steps.MarkStep.MarkAssembly(AssemblyDefinition assembly, DependencyInfo reason)
   at Mono.Linker.Steps.MarkStep.MarkModule(ModuleDefinition module, DependencyInfo reason)
   at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, Nullable`1 origin)
   at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, Nullable`1 origin)
   at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, Nullable`1 origin)
   at Mono.Linker.Steps.MarkStep.MarkField(FieldDefinition field, DependencyInfo& reason, MessageOrigin& origin)
   at Mono.Linker.Steps.MarkStep.MarkEntireType(TypeDefinition type, DependencyInfo& reason)
   at Mono.Linker.Steps.MarkStep.MarkEntireType(TypeDefinition type, DependencyInfo& reason)
   at Mono.Linker.Steps.MarkStep.MarkEntireAssembly(AssemblyDefinition assembly)
   at Mono.Linker.Steps.MarkStep.MarkAssembly(AssemblyDefinition assembly, DependencyInfo reason)
   at Mono.Linker.Steps.MarkStep.MarkModule(ModuleDefinition module, DependencyInfo reason)
   at Mono.Linker.Steps.MarkStep.ProcessMarkedPending()
   at Mono.Linker.Steps.MarkStep.Initialize()
   at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
   at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
   at Mono.Linker.Pipeline.Process(LinkContext context)
   at Mono.Linker.Driver.Run(ILogger customLogger)
   at Mono.Linker.Driver.Main(String[] args)

我比对了我的项目和新建的空的blazor项目的csproj文件没有区别。 参考:https://learn.microsoft.com/zh-cn/dotnet/core/compatibility/serialization/8.0/publishtrimmed 后,我在FolderProfile.pubxml设置如下:

<PropertyGroup>
  <PublishTrimmed>true</PublishTrimmed>
  <JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup>

问题一样,我尝试下面的操作,也没用。

<PublishTrimmed>false</PublishTrimmed>

貌似编译为wasm的部分始终会做裁剪。

你有空帮我看看吗?

复现步骤:

  1. 下载源码 直接下载源码:https://gitee.com/bxjg1987_admin/abp/releases/tag/0.0.3 或克隆:https://gitee.com/bxjg1987_admin/abp
  2. vs2022打开ZLJ.sln
  3. ZLJ.RCL中引用了肉夹馍,默认是2.x版本;ZLJ.Web.BlazorAuto是blaozr web app的服务端项目(ZLJ.Admin.CoreRCL是客户端项目)
  4. 发布ZLJ.Web.BlazorAuto项目,是正常的
  5. ZLJ.RCL项目中,把肉夹馍引用的版本改为3.0
  6. 再次发布ZLJ.Web.BlazorAuto
  7. 此时报错

再次感谢!这些高端操作对我来说太复杂了,不晓得从何下手,望大佬指点。

inversionhourglass commented 3 months ago

描述很详细,感谢反馈,将尽快处理该问题

inversionhourglass commented 3 months ago

这个是pdb调试信息方面的问题,在3.0版本中为了支持方法步入调试做出的相关改动,目前已修复,已发布3.0.1

另外我注意到你的项目为了规避肉夹馍不支持热重载问题而加了很多#if !DEBUG,这个数量多了写起来就会比较折磨,其实有更简单的方式。在项目中任一cs代码文件中添加以下代码(比如GlobalUsing.cs):

#if DEBUG
[assembly:Rougamo.IgnoreMo]
#endif

IgnoreMoAttribute在不传入任何参数的情况下会禁用当前项目所有的肉夹馍特性,当然,也可以传入参数忽略指定类型,具体使用方法可以看README中的 忽略织入

bxjg1987 commented 3 months ago

万分感谢!忽略织物建议也非常有用。