I have a WCF service that uses named pipes. Apparently doesn't use the url for the name. It generates a GUID from the url, then stores it in a memory mapped file. So I wrote a C++ app that gets the name of the pipe from the memory mapped file, and that works great. Now I'm trying to make a c# app that gets the name of the pipe from the memory mapped file. here is the code that I'm using.
private static string GetPipeName(string mappedFileName)
{
var mappedFile = MemoryMappedFile.OpenExisting(mappedFileName, MemoryMappedFileRights.Read);
var bytes = new List<byte>();
using (MemoryMappedViewStream s = mappedFile.CreateViewStream())
{
using (var b = new BinaryReader(s))
{
bytes = b.ReadBytes((int)b.BaseStream.Length).ToList();
}
}
var sb = new StringBuilder();
foreach (var b in bytes)
{
sb.Append(b.ToString("x2"));
sb.Append(" ");
}
Console.WriteLine(sb.ToString());
return sb.ToString();
}
At the first using
statement I get an UnauthorizedAccessException, that says "Access to the path is denied."
I was able to step through and confirm that the filename is the same that I use in the c++ app and that shows when I use the SysInternals tool Handle.exe
Why would the C# app get an access denied? As far as I can tell both are running as the same user.
you need to use the following
CreateViewAccessor(Int64, Int64, MemoryMappedFileAccess);
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