I am calling a function from a native .NET dll like this:
string v = myDLL.GetValueFromString("header");
MessageBox.Show(v);
Upon execution of the program, I get this weird error (on the line which executes this function): "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
What does this error message mean? And is there a way to fix this problem?
This is an AccessViolationException. It is a 'hard' exception, the processor actually crashes trying to execute the machine code. Usually because it is trying to access unmapped memory through a bad pointer value. It is all too common with native code, especially the kind of code that works with C strings.
I'm going to guess that you didn't write this code, you'll need help from the author. Send him a small test program that reproduces the problem. If you want a shot at debugging this yourself then you need the source code for the DLL and switch the debugger to mixed mode so that you can debug both your C# and the native code. Project + Properties, Debug tab, tick the "Enable unmanaged code debugging" option. Set a breakpoint in the native function you are calling.