Memory Mapped File in ISAPI or ASP.NET - FileNotFoundException

1k views Asked by At

I am writing a program in .NET4 which generates Memory Mapped Files in this way: MemoryMappedFile.CreateNew("TEST", int.MaxValue))

I have created ISAPI module which is instaled on IIS7, this module would read MemoryMappedFile but unfortunately it does not work, I get an error: System.IO.FileNotFoundException: Unable to find the specified file.

The Program is on the same PC as IIS7, IIS works on the same user as my program. If I put my code from ISAPI to another program and I can read MemoryMappedFile without any problems.

The same problem occours when I use my code (which read MemoryMappedFile) in ASP.NET. It looks like IIS blocked MemoryMappedFile between system aplication and ISAPI or ASP.NET.

How to solve it? MemoryMappedFile is important to me.

Thanks

2

There are 2 answers

1
Evan M On

Without being able to look at the code in question, I can suggest some avenues of investigation:

  • Are you certain that the handle still exists at the time you are attempting to access it via the ISAPI extension? If the process that created the file is no longer running, it will be garbage-collected and will not be found. You can use Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653) to search for your memory-mapped file (it will appear as a handle of type "section").

  • If that doesn't work, try having your ISAPI extension allocate its own memory-mapped file and see if it can read it's own files.

  • Try allocating a lower capacity to the memory mapped file - setting the capacity to 4 GB as in your example might be the issue.

0
Myk Willis On

The problem could be a namespace issue, the result of trying to share the same memory-mapped file by name between two sessions. As IIS is running as a service, it runs in 'session 0', while other user applications will run in a different interactive session. Each session has its own namespace for named resources (like memory-mapped files).

Try prepending "Global\" to the filename, like:

MemoryMappedFile.CreateNew(@"Global\TEST", int.MaxValue))