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=2.0.0.0, 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!

Advertisements




Creating a Windows Service

26 06 2009

This was something I needed to do recently. And although I found lots of places to help me with understanding how the service would work, the main problem I had was finding somewhere to show me how to create a proper installer/setup project for it.  The MSDN site walkthrough was by far the best for this, so I’m putting the link here, so when I need it again I can find it 🙂

http://msdn.microsoft.com/en-us/library/aa984464(VS.71).aspx

UPDATE:

I was just creating a Windows Service again. My first one I’ve done in quite a while! I came here for the link and the one above is quite out of date now (it’s for VS 2003). So here’s a more up to date one!

http://msdn.microsoft.com/en-us/library/zt39148a.aspx