System.IO.Exception error: "The requested operation cannot be performed on a file with a user-mapped section open."

Looks like another process had the file open using the file mapping (shared memory) APIs.

The find function in Process Explorer should be able to tell you.


It looks like the file you're trying to write is already open elsewhere, either by your code or by another process.

Do you have the file open in an editor? Do you have some other code that reads it, but forgets to close it?

You can use Process Explorer to find out which process has open file handle on it - use the Find / Find handle or DLL... command.


Try excluding the file from your project while you debug. I found that it was in fact VS2010 which was holding the XML file. You can then select "Show all files" in your solution explorer to check the XML file post debug.

A lock will stop the issue when doing multiple writes.

lock(file){ write to file code here }