UnauthorizedAccessException on MemoryMappedFile in C# 4

后端 未结 4 1913
醉梦人生
醉梦人生 2021-01-11 12:20

I wanted to play around with using a MemoryMappedFile to access an existing binary file. If this even at all possible or am I a crazy person?

The idea would be to ma

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-11 12:33

    I know this is an old question, but I just ran into the same error and was able to solve it.

    Even though I was opening the MemoryMappedFile as read-only (MemoryMappedFileRights.Read) as you are, I also needed to create the view accessor as read-only as well:

    var view = mmf.CreateViewAccessor(offset, size, MemoryMappedFileAccess.Read);
    

    Then it worked. Hope this helps someone else.

提交回复
热议问题