Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 10 Creators update .net 4.7 System.AccessViolationException issue

Tags:

c#

.net

.net-4.7

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?

like image 877
Andrew Avatar asked Apr 20 '17 12:04

Andrew


1 Answers

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.

like image 128
Brian Sullivan Avatar answered Oct 21 '22 00:10

Brian Sullivan