none
Attempted to read or write protected memory on windows 10 c# app. RRS feed

  • Question

  • I have met interesting bug in с# core on Windows 10TP build 10041.

    Code like this:

    //WinForms app
    int example1(int a, int b, int c) { return a+b+c; }
    or
    //WPF app
    void example2()
    {
    //some code
    int x = int.Parse("10");
    //more code
    }

    Rises exception like this (being more precise, this log is from the 2-nd example, but "HResult=", "Message=" and "Source=" are the same in both cases):

    System.AccessViolationException was unhandled
      HResult=-2147467261
      Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
      Source=WindowsBase
      StackTrace:
           at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
           at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
           at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
           at System.Windows.Application.RunDispatcher(Object ignore)
           at System.Windows.Application.RunInternal(Window window)
           at System.Windows.Application.Run(Window window)
           at System.Windows.Application.Run()
           at Mapsui.Samples.Wpf.App.Main() in F:\mapsuiwpf\Samples\Mapsui.Samples.Wpf\obj\Debug\App.g.cs:line 0
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:


    I have solved the problem in the first case, using "assembler intuition":

    int example1(int a, int b, int c)
    {
    int temp = a+b+c;
    return temp;
    }


    This is quite tricky way, but I still don`t know, how to solve "example2" issue.
    Can anybody provide me some help, please?
    Link to the bug-fix patch will be handy, but I will thank you even for some voodoo, like in ex1.
    Thank you in advance, dear reader.

    p.s. Hope, you`ll excuse me for my poor English.



    • Edited by Ael_Deyr Friday, May 8, 2015 9:17 PM
    Friday, May 8, 2015 8:57 PM

All replies

  • "I have solved the problem in the first case, using "assembler intuition":"

    If that does indeed fix the issues then I think the only explanation is that there is a bug in the .NET JIT compiler. But that Windows 10 build contains who knows what version of .NET, probably older than that the current .NET 4.6 RC. You should try this on a released version of Windows (7,8,8.1) with .NET 4.6 RC to see if the crash persists.

    Sunday, May 10, 2015 6:47 AM
    Moderator
  • Sorry, I had no time to reach the main computer with win 8.1, but I have found another thing:
    The second aforesaid bug appears only in "step-by-step" debugging. In "f5-debuging" through breakpoints everything is perfect.






    • Edited by Ael_Deyr Monday, May 11, 2015 7:22 PM
    Monday, May 11, 2015 7:11 PM