UnauthorizedAccessException when accessing DLL

Hello,

I’m facing the following error in Unity 4.5.3f3 on Windows 8.1 when trying to load a DLL:

UnauthorizedAccessException: Access to
the path
‘C:/Users/Angela/GIT/UWYO/3DiA/NUI/Unity
integration/Assets/’ is denied.
System.IO.FileStream…ctor
(System.String path, FileMode mode,
FileAccess access, FileShare share,
Int32 bufferSize, Boolean anonymous,
FileOptions options) (at
/Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/FileStream.cs:259)
System.IO.FileStream…ctor
(System.String path, FileMode mode,
FileAccess access, FileShare share)
(wrapper remoting-invoke-with-check)
System.IO.FileStream:.ctor
(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
System.IO.File.Open (System.String
path, FileMode mode) (at
/Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:347)
Plugins.CreateFileFromAsset
(System.String filename) (at
Assets/Plugin/VRPNWrapper/Plugins.cs:159)
VRPNManager.ParseConfigFile () (at
Assets/Plugin/VRPNWrapper/VRPNManager.cs:202)
VRPNManager.Start () (at
Assets/Plugin/VRPNWrapper/VRPNManager.cs:129)

This is followed by:

DllNotFoundException:
VRPNWrapper/VRPNWrapper
VRPNManager.Update () (at
Assets/Plugin/VRPNWrapper/VRPNManager.cs:164)

I have seen a lot of people having that problem in Windows 8.1 and the solutions that have worked for them don’t work for me. What I have tried so far:

  • Running Unity as administrator: didn’t work
  • Disabling antivirus (AVG): didn’t work
  • Checking the permissions of my Assets and VRPNWrapper folder (where the DLL is): I have even given permissions to Everyone and it doesn’t fix the problem.
  • I have even run auditpol /clear

I have even thought that Unity is not using my username when trying to access the DLL folder, but in that case, to what user I should gave permissions ?

I finally found the problem !

Actually those are two different problems:

UnauthorizedAccessException

Check that the error mentions a file operation and “C:/Users/Angela/GIT/UWYO/3DiA/NUI/Unity integration/Assets/”, the problem is that the library I’m using (VRPNWrapper) is trying to open that path as if it were a file, so the access is not denied for a matter of permissions, it is denied because the operation is illegal (opening a directory to read its contents). The solution was to configure that library with the correct filename that it was missing.

DllNotFoundException

This is a misleading error message, Unity is not failing to find my DLL, it’s failing to load it. The reason is that this DLL depends on other DLLs that are not present in my system.
Using Dependency Walker helped me to understand the load chain and find which DLLs were missing.

I hope this information may guide others.