ArxOne / MrAdvice

.NET aspect weaver (build task under NuGet package)
MIT License
311 stars 45 forks source link

Weaving produces illegal IL code with generic ref argument. #160

Closed Shakesfear closed 4 years ago

Shakesfear commented 4 years ago

A sample applications which produces this issue is:

namespace TestApplication { using System;

class Program2
{
  static void Main(string[] args)
  {  
    B b = new B();
    int c = 0;
    b.M<int>(ref c);
    Console.ReadLine();
  }
}

[LoggerAdvice]
public class B {

  public void M<T>(ref T i)
  {
    Console.WriteLine("Hallo! " + i);
  }
}

}

[AttributeUsage(AttributeTargets.Class)] public class LoggerAdvice : Attribute, IMethodAdvice { public void Advise(MethodAdviceContext context) { Console.WriteLine($"Enter Method " + context.TargetName); context.Proceed(); Console.WriteLine($"Exit Method " + context.TargetName); } }

perefy.bat then complains: Severity Code Description Project File Line Suppression State Error The command ""C:\Projects\MrAdvice-master\Tools\peverify.bat" "C:\Projects\MrAdvice-master\Test\TestApplication\bin\Debug\TestApplication.exe"" exited with code 1. TestApplication C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets 5165
Error [C:\Projects\MrAdvice-master\Test\TestApplication\bin\Debug\TestApplication.exe : TestApplication.TestApplication.B::M[T]][offset 0x0000000B][found (unboxed) 'T'] Expected an ObjRef on the stack.(Error: 0x8013185E) TestApplication C:\Projects\MrAdvice-master\Test\TestApplication[IL]

I was using the latest code from master.

MrAdvice.2.8.9-embed1\lib\net40-client\MrAdvice.dll which we were using in our productive code seems to have the same issue.

Other than that: Awesome library :-)

picrap commented 4 years ago

This look like a real bug... 😉 I'll see what I can do.

picrap commented 4 years ago

Could you confirm it works for you (v2.8.10)?