Skip to content

ILGenerator.BeginFinallyBlock example is invalid #3592

Open

Description

@svick

As discovered by @luboid in https://github.com/dotnet/coreclr/issues/14379#issuecomment-334959413, the example code for ILGenerator.BeginFinallyBlock contains branch out of try block and is thus invalid. When I run it on .Net Framework 4.7 in x64 mode or .Net Core 2.0 (after changing myAppDomain.DefineDynamicAssembly to AssemblyBuilder.DefineDynamicAssembly and removing the permissions attribute to make it compile on .Net Core 2.0), I get the following exception:

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at Adder.DoAdd(Int32 , Int32 )
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
   at ILGenerator_BeginFinallyBlock.Main() in C:\code\tmp\coreapp\Program.cs:line 109

I think the example should be changed, so that it produces valid IL.

Activity

  1. mairaw commented on Oct 9, 2017

    @mairaw
    Contributor

    Thanks @svick for reporting this issue. We're adding this item to our backlog.

  2. garg000dhruv commented on Oct 19, 2017

    @garg000dhruv

    @mairaw I can take this up if you'd like.

  3. rpetrusha commented on Oct 19, 2017

    @rpetrusha

    If you would like to work on this, @garg000dhruv, that would be really great. .
    Incidentally, although the ECMA spec explicitly disallows a return from a try region, it was not enforced until the new 64-bit JIT compiler introduced in the .NET Framework 4.6. See "IL ret not allowed in a try region" in the list of app compat issues between 4.5 and 4.6.

  4. garg000dhruv commented on Oct 19, 2017

    @garg000dhruv

    @rpetrusha That's what I was wondering because when I run the example on my machine, it runs just fine. I'll try with the updated specs and see what happens. But yeah I'd love to take this one up.

  5. garg000dhruv commented on Oct 20, 2017

    @garg000dhruv

    @mairaw Let me know if I can start work on this. I only asl because I didn't see the up-for-grabs label removed or the issue moved to to-do.

  6. rpetrusha commented on Oct 20, 2017

    @rpetrusha

    @garg000dhruv, you can start work on this issue. I've removed the up-for-grabs label. Since the issue is not part of a project, though, it can't be moved to either to-do or in-progress. We'll set the milestone when your PR arrives.

  7. transferred this issue fromdotnet/docson Dec 3, 2019
  8. added
    untriaged
    on Dec 3, 2019
  9. added
    Pri3
    on Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3area-System.Reflection.Emituntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions