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

Exception filter causes lockup when exception thrown from instance method #177

Open
rickmas opened this Issue Feb 16, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@rickmas

rickmas commented Feb 16, 2018

TinyCLR 0.8.0
VS2017
FEZ Spider (EMX)

In the following contrived example, when the catch (...) when (...) expression evaluates to true the system locks up and control never falls into the catch block. I'm forced to pull power from my board and erase/reload firmware every time.

using System;

namespace MaschMaker
{
    public class TestANE
    {
        public void ThrowANE() { throw new ArgumentNullException(paramName: "ANE", message: "some message"); }
    }

    class Program
    {
        static void Main()
        {
            try
            {
                new TestANE().ThrowANE();
            }
            catch (ArgumentNullException e) when ("ANE" == e.ParamName)
            { }
        }
    }
}

Removing the when () expression makes it work just fine

            catch (ArgumentNullException e) //when ("ANE" == e.ParamName)

OR

keeping the when () expression but changing ThrowANE() to a static method also works, probably because Main() is static.

using System;

namespace MaschMaker
{
    public class TestANE
    {
        public static void ThrowANE() { throw new ArgumentNullException(paramName: "ANE", message: "some message"); }
    }

    class Program
    {
        static void Main()
        {
            try
            {
                //new TestANE().ThrowANE();
                TestANE.ThrowANE();
            }
            catch (ArgumentNullException e) when ("ANE" == e.ParamName)
            { }
        }
    }
}

OR

keeping the when () expression but moving ThrowANE() to be a local method works. This is probably the same case as using a static method but was another test I did.

using System;

namespace MaschMaker
{
    class Program
    {

        static void Main()
        {
            void ThrowANE() { throw new ArgumentNullException(paramName: "ANE", message: "some message"); }

            try
            {
                //new TestANE().ThrowANE();
                //TestANE.ThrowANE();
                ThrowANE();
            }
            catch (ArgumentNullException e) when ("ANE" == e.ParamName)
            { }
        }
    }
}

I obviously have a workaround but would like to use the exception filters if possible.

@Arke64

This comment has been minimized.

Member

Arke64 commented Feb 19, 2018

We were able to reproduce it, and not just on the EMX. The generated IL is nearly identical too. So it looks to be a problem in the runtime.

@Arke64 Arke64 self-assigned this Feb 19, 2018

@Arke64 Arke64 added this to the v0.9.0 milestone Feb 19, 2018

@Arke64 Arke64 added the bug label Feb 19, 2018

@Arke64 Arke64 modified the milestones: v0.9.0, v1.0.0 Feb 19, 2018

@Arke64 Arke64 modified the milestones: v0.10.0, v0.11.0 Mar 29, 2018

@Arke64 Arke64 modified the milestones: v0.11.0, v0.12.0 Apr 23, 2018

@Arke64 Arke64 modified the milestones: v0.12.0, v1.0.0-preview1 Jun 21, 2018

@Arke64

This comment has been minimized.

Member

Arke64 commented Aug 7, 2018

We've done a bit more investigation and it seems the problem occurs because the handler is too close to the end of the method, which triggers an assert validating bytecode boundaries. For example, blinking an LED after the try/catch was enough to let it work. That's also why you could rearrange things slightly to get it to work. We don't yet have an actual fix but we are continuing to investigate.

@Arke64 Arke64 modified the milestones: v1.0.0-preview1, Backlog Aug 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment