Bug 8787 - MemoryMappedFile.CreateViewAccessor always fails
Summary: MemoryMappedFile.CreateViewAccessor always fails
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.0.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-12-05 18:28 UTC by Frank A. Krueger
Modified: 2014-06-19 17:00 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Repro project (3.77 KB, application/zip)
2012-12-05 18:28 UTC, Frank A. Krueger

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Frank A. Krueger 2012-12-05 18:28:19 UTC
Created attachment 3063 [details]
Repro project

I am trying to create access a memory mapped file:

using (var mm = MemoryMappedFile.CreateFromFile ("TestFile.txt", FileMode.Open, null, 0L, MemoryMappedFileAccess.Read)) {
	using (var acc = mm.CreateViewAccessor ()) {

But it always fails with this exception:

[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: mmap failed for fd#9(0, 34)
  at System.IO.MemoryMappedFiles.MemoryMapImpl.Map (Int32 file_handle, Int64 offset, System.Int64& size, MemoryMappedFileAccess access, System.IntPtr& map_addr, System.Int32& offset_diff) [0x000da] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.IO.MemoryMappedFiles/MemoryMappedFile.cs:413 
  at System.IO.MemoryMappedFiles.MemoryMappedViewAccessor.Create (Int64 offset, Int64 size, MemoryMappedFileAccess access) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.IO.MemoryMappedFiles/MemoryMappedViewAccessor.cs:71 
  at System.IO.MemoryMappedFiles.MemoryMappedViewAccessor..ctor (Int32 file_handle, Int64 offset, Int64 size, MemoryMappedFileAccess access) [0x0000d] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.IO.MemoryMappedFiles/MemoryMappedViewAccessor.cs:46 
  at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewAccessor (Int64 offset, Int64 size, MemoryMappedFileAccess access) [0x00027] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.IO.MemoryMappedFiles/MemoryMappedFile.cs:617 
  at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewAccessor (Int64 offset, Int64 size) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.IO.MemoryMappedFiles/MemoryMappedFile.cs:610 
  at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewAccessor () [0x00000] in <filename unknown>:0 
I have attached a minimal repro project.
Comment 1 Michael 2013-11-21 21:06:06 UTC
I also have the same problem. Do we have any updates?
Comment 2 Rodrigo Kumpera 2014-06-19 17:00:04 UTC
This is not a bug in mono.

The no argument CreateViewAccessor tries to create a read write view of a read only file, which will, of course, fail.

Either pass MemoryMappedFileAccess.ReadWrite to CreateFromFile or use the right CreateViewAccessor overload.