-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature request] Allow set custom attributes on inner method #205
Comments
The attributes are still there, I don’t understand why this happens. |
csproj file: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net462</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MrAdvice" Version="2.15.0" />
</ItemGroup>
</Project> Program.cs: using System.Runtime.ExceptionServices;
using System.Security;
using ArxOne.MrAdvice.Advice;
internal class Program
{
public static void Main(string[] args)
{
TestMethod();
}
[Test]
[HandleProcessCorruptedStateExceptions]
[SecurityCritical]
private static void TestMethod()
{
Console.WriteLine("May throw System.AccessViolationException here.");
}
}
public class TestAttribute : Attribute, IMethodAdvice
{
public void Advise(MethodAdviceContext context)
{
context.Proceed();
}
} Generateed Code (decompiled): using ArxOne.MrAdvice;
using ArxOne.MrAdvice.Annotation;
using System;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Security;
#nullable enable
internal class Program
{
public static void Main(string[] args) => Program.TestMethod();
[Test]
[HandleProcessCorruptedStateExceptions]
[SecurityCritical]
private static void TestMethod()
{
// ISSUE: method reference
// ISSUE: method reference
// ISSUE: method reference
⚡Invocation.ProceedAspect(__methodref (Program.TestMethod), __methodref (Program.TestMethod′), __methodref (Program.TestMethod″));
}
[ExecutionPoint]
private static void TestMethod′()
{
Console.WriteLine("May throw System.AccessViolationException here.");
}
private static
#nullable disable
object TestMethod″([In] object obj0, [In] object[] obj1)
{
Program.TestMethod′();
return (object) null;
}
} As you can see, the generated method |
Sorry for huge delay. I’ve been thinking to this problem and I don’t know how to solve this.
So how to solve this ?
Adding custom attributes beside the |
In most cases, the current solution works well. However, the |
The problem:
When calling extern method, it may throw
System.AccessViolationException
, which can not be catched and will crashes the process.To catch this exception (.NET Framework only), the caller must set two attributes on current method:
HandleProcessCorruptedStateExceptionsAttribute
andSecurityCriticalAttribute
.But the weaver did not copy these attributes to the generated innner method, and causes the process crash.
Possible solution
This is the easist but not the best, because it takes extra steps to check attributes.
Users can set attributes based on their logic.
The text was updated successfully, but these errors were encountered: