dotnet / machinelearning-samples

Samples for ML.NET, an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
4.49k stars 2.69k forks source link

System.AccessViolationException: 'Attempted to read or write protected memory #956

Open billkearson opened 2 years ago

billkearson commented 2 years ago

System Windows 10 VS 2022

Download samples and tried to run the program: OnnxObjectDetection

Complies correctly and when I run the program an unhandled exception is thrown on line 25 var pipeline.

"An unhandled exception of type 'System.AccessViolationException' occurred in Microsoft.ML.OnnxRuntime.dll Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

The program '[19772] OnnxObjectDetectionApp.exe' has exited with code 3221225477 (0xc0000005) 'Access violation'."

Tried running VS 2022 as administrator and same issue. Tried changing to x64, x86, and Any CPU and same issue. Even rebooted same issue. Stuck.

Other samples such as DeepLearning_ObjectDetection_Onnx work fine, no issues.

Thank you.

Ottodeklerk commented 2 years ago

Try updating OpenCvSharp-AnyCPU to OpenCvSharp4. Also install the runtime for your OS. In case of Windows that is OpenCvSharp4.runtime.win

To be sure, you can also update the Microsoft.ML.* packages.

michaeltclark commented 2 years ago

Windows 10 VS 2022 .Net 6

Confirming that updating Microsoft.ML packages (to 1.7.1) and changing .Net target to .Net 6 worked for me. I did not need to make any changes to OpenCvSharp.

eduardomb08 commented 1 year ago

Windows 10 VS 2022 .Net 6

Tried the workaround suggested by @michaeltclark and it did NOT work for me.