From what I can see:
Your send string func might be wrong because you have to send the string.length + 1 due to null terminator.
I also dont know why you call Marshal.FreeHGlobal(ptr) since you only received the pointer (unless you _want_ to erase the data after sending).
In your "object to_struct" you should add a check for the pointer not being null.
Otherwise I cant see a real error here, but Im not really good with C# anyways
Hope that helped a bit