Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

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

$
0
0

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.




Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>