System.AccessViolationException

Strong, Brandon J 1 Reputation point
2022-08-17T16:35:16.517+00:00

Hello!

I am having this error message:
System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>

About the error:
I am using C# on .NET Framework 4.8. The error is very inconsistent, it can happen within a few seconds, or in 10 minuets. This error appears both in release, and debug mode. It seems to happen faster when it's in release mode.
These are the packages that I'm using
- ClosedXML (0.96.0)
- AForge (2.2.5)
- AForge.Imaging (2.2.5)
- AForge.Math (2.2.5)
- Emgu.CV (4.3.0.3890)
- Emgu.CV.runtime.windows (4.3.0.3890)
- ExcelNumberFormat (1.1.0)
- ZedGraph (5.1.7)
- Microsoft.CSharp (4.7.0)
- DocumentFormat.OpenXml (2.16.0)

This is where it happens in the code:
232121-code.png

Here is an image of the quick watch:
232107-quickwatch.png

I have looked at quite a few different threads and I can't seem to figure out how to fix this issue.

These are the things that I've tried so far:

  1. Changing solution platforms to be x64, x86, or AnyCPU (I cleaned and rebuilt the solution after each of these changes)
  2. Enabled native code debugging
  3. "Suppress JIT optimization on module load" in: Tools menu ->Options -> Debugging -> General
  4. Switching Emgu.cv to EmguCV
  5. Removing non-essential NuGet packages
  6. Changing the version of the NuGet packages

From here I'm not really sure what else to try, would appreciate any feedback.

Thanks in advance! :)

Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Strong, Brandon J 1 Reputation point
    2022-08-22T17:25:46.173+00:00

    I figured out the issue.

    The issue was that the function that was being called to do the thresholding was a form event. The Timer was calling that function. Switching thresholding to be a normal function fixed the issue.

    Original function:
    233712-original-function.png

    Original Call:
    233693-timer-calling.png

    New function:
    233672-auto-threshfunction.png

    New Call:
    233751-timer-now-calls.png

    Thanks for the help! :)

    Have a great day.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.