What can cause the error:
Attempting to read or write protected memory. This often indicates that the other memory is damaged.
A project is written in c # and dll in c ++, compiled separately without errors, but when you run the project, it reaches the second function (written in dll) and gives this error.