Oh I am sorry.
The exception is raised when I try to write the struct in memory mapped file i.e. this line - SharedData.Writer = MemWriterObj;
I have marshalled mystring hoping that it would solve the problem but it doesn't.
Any idea how I can make it work?
Basically what the error is saying is "you can't do that at all".
A struct is a value type - it contains all it's information directly within the struct itself, and teh size is always fixed at compile time. "Basic types" such as int, float, and double are also value types.
A string is a reference type - the variable you declare is not the string itself but a reference to the memory that actually contains the string data - the reference itself is a fixed size, but teh data it refers to is not.
The error message is saying "you can only give me fixed size data" - a value type, not a reference type - and that it cannot contain any references.
So the struct you pass through can only contain basic types, and structs containing basic types - no reference types, which means no strings, no arrays, no Lists, nothing complex at all.
I suspect you are going to have to find a better solution to your problem, and drop the idea of memory mapped files altogether. What exactly are you trying to do that you think you need these?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
@OrigianlGriff...That is the reason I used MarshalAs(UnmanagedType.ByValTStr,SizeConst=16)] public string mystring;
Which gives my string a fixed size(16) if I am not wrong.
I am trying to create an application which writes to a memory mapped file("test"). There will be another application which reads from the same memory mapped file and performs the specified operation.