How to resolve UnauthorizedAccessException?

Running Unity 5.1.1f1

I’ve tried different patcher plugins on the unity store, and each of them keep giving me the same, or similar error.

UnauthorizedAccessException: Access to the path "I:/Unity/Mimycx/MGPatcherBuilder/Win/x86/content/1\Mimycx_Data\Managed\DialogueSystem.dll" is denied.
System.IO.File.Delete (System.String path) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:179)
System.IO.Directory.RecursiveDelete (System.String path) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/Directory.cs:195)
System.IO.Directory.RecursiveDelete (System.String path) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/Directory.cs:190)
System.IO.Directory.RecursiveDelete (System.String path) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/Directory.cs:190)
System.IO.Directory.Delete (System.String path, Boolean recursive) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/Directory.cs:205)
MGPatcherToolsScript.copyToSource (Int32 countArray, System.String platform_name) (at Assets/MGPatcherTools/MGPatcherBuilder/Editor/MGPatcherToolsScript.cs:757)
MGPatcherToolsScript.buildGame () (at Assets/MGPatcherTools/MGPatcherBuilder/Editor/MGPatcherToolsScript.cs:739)
MGPatcherToolsScript.OnGUI () (at Assets/MGPatcherTools/MGPatcherBuilder/Editor/MGPatcherToolsScript.cs:370)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

MGPatcherToolsScript ln 739
calls a function defined a couple lines further down. Inside of this function is a line (757) that has an if on condition:

Directory.Exists(...+"content/"+...)

If the directory exists, it calls

Directory.Delete(...+"content/"+...,true);

I’ve come to the conclusion that it is trying to delete the dialoguesystem.dll, which is a dll for another plugin that’s vital to my project. Any ideas how to remedy the situation?

I’ve already made sure I’ve got administrator privileges and that Unity is in fact being run in Administrator.

I should note; I have made a very tiny example project with the patcher that worked with a nearly empty scene.

alrighty, I solved this one myself.

Every time I built the project using the patcher tool, it would throw the UAException. To remedy this I had to place

  File.SetAttributes ("I:/Unity/Game/MGPatcherBuilder/Win/x86/content/2\\Game_Data\\StreamingAssets\\build_info.txt",
	                    File.GetAttributes ("I:/Unity/Game/MGPatcherBuilder/Win/x86/content/2\\Game_Data\\StreamingAssets\\build_info.txt")
		& ~FileAttributes.ReadOnly);

The first line set’s the file attribute, writable, archived, hidden, readonly, etc.

The first argument on the first line is the path, the second argument is on lines 2 and 3.

Line 2 is the original file attributes. Line 3 modifies the original file attributes using a bitmask. Line 3 removes the ReadOnly attribute.

I had to place this code generously before any code that accesses my .dll’s

Once I did this, building individual versions worked.

The patching process also threw a UAException. To remedy this issue I placed

public static string GetMD5HashFromFile (string fileName)
{
//added this to fix UAException
File.SetAttributes (fileName, File.GetAttributes (fileName) & ~FileAttributes.ReadOnly);…}

Inside MGPatcher’s static function lib.

I had to change each individual file from readonly to not readonly. Modifying the directory’s attribute didn’t work. Modifying all of the files at once in a foreach loop did not work.

Sometime during the instructions, the files get changed back to readonly. If I changed them all to writable eventually they got changed back to readonly. This would produce UAExceptions but on variable .dll’s

If anyone knows of a better solution, please pitch in