none
MemoryMappedFile.CreateOrOpen throwing InvalidOperationException RRS feed

  • Question

  • Using .NET 4.0, I have some code that is calling MemoryMappedFile.CreateOrOpen that works fine in Windows 7 and Windows 2008 R2, but recently a coworker got a Windows 8 laptop and the call to CreateOrOpen is throwing a InvalidOperationException with the message "Cannot create file mapping" on his machine.

    This is especially strange since according to the documentation (http://msdn.microsoft.com/en-us/library/dd267593(v=vs.100).aspx) that function should not be able to throw that exception. Below is the relevant code samples in VB.NET.

    Public Const LOG_MEMFILE As String = "Global\errorlogmemfile"
    Public Const LOG_MEMFILE_CAPACITY As Integer = 100000
    
    ...
    
    Dim customSecurity As New MemoryMappedFileSecurity()
    customSecurity.AddAccessRule(New AccessRule(Of MemoryMappedFileRights)(New SecurityIdentifier(WellKnownSidType.WorldSid, Nothing), MemoryMappedFileRights.FullControl, AccessControlType.Allow))
    _errorMemFile = MemoryMappedFile.CreateOrOpen(LOG_MEMFILE, LOG_MEMFILE_CAPACITY, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.DelayAllocatePages, customSecurity, HandleInheritability.None)

    Any explanation and/or fix for this phenomenon would be appreciated.


    Saturday, September 7, 2013 2:50 AM

Answers

  • Is your coworker running the application as administrator? Creating a file mapping object in the Global namespace requires administrative rights.
    • Marked as answer by StandBeforeZod Saturday, September 7, 2013 9:55 PM
    Saturday, September 7, 2013 4:51 AM
    Moderator

All replies

  • Is your coworker running the application as administrator? Creating a file mapping object in the Global namespace requires administrative rights.
    • Marked as answer by StandBeforeZod Saturday, September 7, 2013 9:55 PM
    Saturday, September 7, 2013 4:51 AM
    Moderator
  • This was actually debugging active development code and he didn't realize that Visual Studio wasn't running as admin on his new box, running Visual Studio as admin fixed the problem.  Thanks!
    Saturday, September 7, 2013 9:57 PM