5

After updating Windows 10 to creators update with .net 4.7 I have a critical issue on starting very simple code.

Description: The process was terminated due to an unhandled exception. Exception Info: System.AccessViolationException

class Program
{
        private int? m_bool;
        private bool prop {get{ return false;}}
        void test()
        {
            //nothing
        }
        private object Test()
        {
            if (prop)
            {                    
                try
                {
                    test();
                }
                catch (Exception) {}

                m_bool = 1;                    
            }
            return null;
        }

        static void Main(string[] args)
        {
            new Program().Test();
        }
}

Seems the similar issue is https://github.com/dotnet/coreclr/issues/10826

Anyone knows how to avoid that?

Andrew
  • 158
  • 8
  • Please note - this works under visual studio and does not on application run in release only. – Andrew Apr 20 '17 at 15:32

1 Answers1

5

The issue is caused when an optimization is running on an unreachable basic block. In your case the compiler inlines the get_prop method (which unconditionally returns false). This leads to JIT compiler to consider the region as unreachable. Typically the JIT compiler removes the unreachable code before we run the optimization, but adding a try/catch region causes the JIT not to delete these basic blocks.

If you want to prevent the issue you could disable optimizations, disable the inlining of get_prop or change the implementation of the get_prop method to be:

    static bool s_alwaysFalse = false;
    private bool prop {get{ return s_alwaysFalse;}}

We have had a couple of reports of this issue and we do have a fix ready and it will be provided to users in a upcoming update.

  • Any advice on how we can prevent horrible bugs like this getting downloaded onto our machines is appreciated. And necessary considering how undiagnosable this is. – Hans Passant Apr 25 '17 at 21:38
  • Thanks Brian for clarification! We have large solution and only one place that fails. Originally the property has some conditional compiling and on some case return false. – Andrew May 05 '17 at 15:29
  • @Brian, when this problem will be fixed, and how the patch will be available to us? – Graviton May 19 '17 at 03:34