File Access Denied

I am trying to reorganize an old piece of code that was paved with a loaf together, in a hurry into something more elegant.

There are two parts to the project: a Windows service and a form application that monitors the activities of services.

To allow this connection, I decided to use an unconfigured file with memory.

Below is the working code in the old project:

var security = new MemoryMappedFileSecurity(); security.AddAccessRule(new AccessRule<MemoryMappedFileRights>("everyone", MemoryMappedFileRights.FullControl,AccessControlType.Allow)); file = MemoryMappedFile.CreateOrOpen(@"Global\" + instance, bufferSize, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.DelayAllocatePages, security, HandleInheritability.Inheritable); 

The above code is located in ctor, which is launched by both the service and the form, they use the same code and work regardless of what mmf creates.

Now I have the same code in a new project, but if the service first creates mmf, then the form receives a path access error message, and if the form creates mmf, then the Service "opens" its side perfectly, but none of them can see the written information, which makes me believe that they actually do not look at the same thing.

At this point, I donโ€™t know where to start debugging the problem, I use the security rule and the Global namespace because of the session isolation.

I just canโ€™t wrap my head around why it works in one, but not in the other.

Any advice on where to go from here would be appreciated. Also, if more code is required, just let me know.

+3
source share
1 answer

So, after much burning, I found the answer to my problem.

Apparently, Visual Studios did not like how I added the file containing this code to my project. I just added "Add Existing".

To solve the problem, I created a new class and copied / pasted the code from another file:

Everything works perfectly.

0
source

Source: https://habr.com/ru/post/1495408/


All Articles