I am tring to open memory mapped file in the system volume information subfolder. I know and see in explorer that it is exists there, and path is correct (it is copy-pasted from explorer), moreover File.Exists for that path returns true, but MemoryMappedFile.OpenExisting fails with DirectoryNotFoundException. Why? (I have all rights to system volume information folder and subfolders).
Some code:
const string filePath = @"C:\\System Volume Information\\Foo\\2.ext";
bool exists = File.Exists(filePath); //is true
using (MemoryMappedFile bitmapFile = MemoryMappedFile.OpenExisting(filePath, MemoryMappedFileRights.Read)) //Throws DirectoryNotFoundException
{
...
}
The exception that is thrown when part of a file or directory cannot be found. [ System.Serializable ] public class DirectoryNotFoundException : System. IO. IOException [ System.Serializable ] [ System.Runtime.InteropServices.ComVisible (true) ] public class DirectoryNotFoundException : System. IO. IOException
If your code does not have PathDiscovery permission, the error message for this exception may only contain file or directory names instead of fully qualified paths. Initializes a new instance of the DirectoryNotFoundException class with its message string set to a system-supplied message and its HRESULT set to COR_E_DIRECTORYNOTFOUND.
Directory.SetCurrentDirectory (dir) Catch ex As System.IO.DirectoryNotFoundException ' Let the user know that the directory did not exist. Console.WriteLine ("Directory not found: " + ex.Message) End Try End Sub End Module
When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. Serves as the default hash function. When overridden in a derived class, sets the SerializationInfo with information about the exception.
You need to use MemoryMappedFile.CreateFromFile("yourPathToFileInDisk", FileMode.Open,"WhateverName") which is opening file you need. MemoryMappedFile.OpenExisting("WhateverName") tries to open already existing memory mapped file.
I haven't used these APIs, but I believe you need to map the file to memory first. Try MemoryMappedFile.CreateFromFile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With