Open yizhang82 opened 8 years ago
@jaredpar This has come up again in relation to some interop scenarios involving porting TlbImp
generated code to .NET Core. Not the most pressing but would be interesting given some of our partners.
@AaronRobinsonMSFT okay, will add it to the C# 10 backlog and see if we can get it in.
Version Used: Visual Studio 2015 Update 2 Steps to Reproduce:
class Test { public extern event System.EventHandler FontChanged { [MethodImpl(MethodImplOptions.InternalCall)] add; [MethodImpl(MethodImplOptions.InternalCall)] remove; } }
Similar code with properties works fine.
This is needed to be able to write interop functions (extern + internalcall) that is implemented by runtime / MCG in C#. Today if you disassemble TlbImp generated IL into C# using ILSpy, you'll observe this exact same problem, which is how I discovered this in the first place.
Expected Behavior:
Roslyn emits extern methods for both add/remove with RVA=0 and InternalCall flags.
This is what I get with properties:
public extern int MyProp { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }
Metadata from ILDASM:
Actual Behavior:
CS0073: An add or remove accessor must have a body