Permissions issues with DLL’s stored on network shared drives

29 06 2009

One of the main things I am currently working on is a windows service that watches for files, and when one is found uses the information in that file, to call a DLL that is stored on a different machine on the same domain on a network shared drive, to do the magic with the information in the file (we will say in this case the DLL was held on MachineA and the service was running on MachineB).

I was having a continuous problem with the following exception:

“Request for the permission of type ‘System.Security.Permissions.SecurityPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.”

It took a lot of surfing the internet and forums, and a lot of book reading to finally find a solution that worked for us.

Due to the DLL being held on a different machine (MachineA), MachineB would not allow it to do anything outside of it’s own scope. For example, it has no access to the file system. Using the caspol utility (see here for information) I added a new url with full trust to the internet group on MachineB using the following command text:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\caspol.exe -addgroup 1.3 -url file:\\ipAddress/folder/* FullTrust

After doing this I restarted my service, and it worked! The nasty security permissions exception went away and it worked as expected. Yey!