Skip to content

Commit

Permalink
#71. Fix the illink Exception when publish a blazor project.
Browse files Browse the repository at this point in the history
  • Loading branch information
inversionhourglass committed Jul 4, 2024
1 parent 6438688 commit 238659b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
14 changes: 2 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
- [#36](https://github.com/inversionhourglass/Rougamo/issues/36) 应用Rougamo的方法支持步入调试
- [#54](https://github.com/inversionhourglass/Rougamo/issues/54) 解决snupkg报checksum错误的问题,需直接依赖Fody,详见issue回复
- [#60](https://github.com/inversionhourglass/Rougamo/issues/60) 支持自定义`AsyncMethodBuilder`
- [#63](https://github.com/inversionhourglass/Rougamo/issues/63) 支持泛型`Attribute<T>`
- [#65](https://github.com/inversionhourglass/Rougamo/issues/65) 修复特定`Type`类型无法作为`MoAttribute`构造方法参数

# 3.0版本对比之前版本差异
3.0版本在代码织入的方式上进行了改变,从原方法内部进行代码织入的方式改为代理方法织入,这样的改变会使Rougamo之前提供的部分功能发生变化:

1.[#53](https://github.com/inversionhourglass/Rougamo/issues/53) 中支持的功能“刷新参数值”现在仅对`out / ref`参数有效
2. `void async`方法无法确保方法切实执行完毕后再执行`OnSuccess`,也无法确保异常一定会进`OnException`
3. `ExMoAttribute`弃用,代理调用的方式不再区分是否使用`async / await`语法
- [[#71](https://github.com/inversionhourglass/Rougamo/issues/71)] 修复blazor项目在发布时illink对程序集做裁减优化时产生的异常
> 程序集主要描述信息基本存储在ModuleDefinition的MetadataSystem字段中,各类型的原数据也基本从该对象中读取。然而通过删除/清空MethodDefinition的CustomDebugInformation并不会影响MetadataSystem中的数据,同时,在将修改写入程序集时,MetadataSystem中绝大部分数据都将直接清空后重新写入,然而CustomDebugInformation是个例外,这就导致MethodDefinition上对CustomDebugInformations的删除/清空操作无效。所以对CustomDebugInformation的删除操作还需要从MetadataSystem中的删除。参考 [MetadataSystem.Clear()](https://github.com/jbevain/cecil/blob/8e1ae7b4ea67ccc38cb8db3ded6802643109ffd7/Mono.Cecil/MetadataSystem.cs#L137)
---
13 changes: 13 additions & 0 deletions src/Rougamo.Fody/Extensions/MonoExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BindingFlags = System.Reflection.BindingFlags;

namespace Rougamo.Fody
{
Expand Down Expand Up @@ -491,12 +493,23 @@ public static void DebuggerStepThrough(this MethodDefinition methodDef, MethodRe

public static void Clear(this MethodDefinition methodDef)
{
methodDef.HardClearCustomDebugInformation();
methodDef.DebugInformation = null;
methodDef.Body.Instructions.Clear();
methodDef.Body.Variables.Clear();
methodDef.Body.ExceptionHandlers.Clear();
}

public static void HardClearCustomDebugInformation(this MethodDefinition methodDef)
{
methodDef.CustomDebugInformations.Clear();

var module = methodDef.Module;
var metadata = module.GetType().GetField("MetadataSystem", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(module);
var customDebugInformations = (IDictionary)metadata.GetType().GetField("CustomDebugInformations", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(metadata);
customDebugInformations.Remove(methodDef.MetadataToken);
}

private static Code[] _EmptyCodes = new[] { Code.Nop, Code.Ret };
public static bool IsEmpty(this MethodDefinition methodDef)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rougamo/Rougamo.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<VersionPrefix>3.0.0</VersionPrefix>
<VersionPrefix>3.0.1</VersionPrefix>
<Authors>ihourglass</Authors>
<Description>Weave code before method execution, on sucessful and on exception. You can replace return value, handle exception and rewrite method arguments. It's both support sync and async method</Description>
<PackageTags>AOP Fody IL</PackageTags>
Expand Down

0 comments on commit 238659b

Please sign in to comment.