I have a WCF service that uses named pipes. It does not seem to use the name url. It generates a GUID from the URL and then saves it in a memory mapped file. So I wrote a C ++ application that gets the channel name from a memory mapped file, and that works fine. Now I'm trying to create a C # application that gets the channel name from a memory mapped file. here is the code i am 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(); }
In the first using statement, I get a UnauthorizedAccessException that says: "Access to the path is denied."
I managed to go through and confirm that the file name matches the one I use in a C ++ application and shows when I use the SysInternals Handle.exe tool
Why will a C # application get denied access? As far as I can tell, both of them work as the same user.
source share