Search Unity

Unhandled Exception: System.UnauthorizedAccessException...?

Discussion in 'Editor & General Support' started by danreid70, Mar 20, 2015.

  1. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    225
    I'm getting the following error that I can't figure out how to fix.

    I upgraded a project from 4.6 to the new 5.0, and it all seemed to work nicely, until the last few days I can't run the game - it won't compile when I click play button and receive the below error in the console.

    Somehow, I noted that there were files marked as read-only in my project and set all files in entire project to not read-only, thinking that had something to do with it, and it worked - a couple times. Now even that doesn't seem to help (it was a shot in the dark).

    I'm running Windows 8 (updated with all service packs). Using Unity Editor 64-bit, for desktop build.

    Any ideas would be greatly appreciated. Anyone else having this problem? Any other information I could give that might help trace this? It's a show-stopper. :eek:
    --Dan


    Unhandled Exception: System.UnauthorizedAccessException: Access to the path "C:\Users\DANNYR\Desktop\UNITY__Cor3volution\Temp\Assembly-CSharp-Editor.dll.mdb" is denied.

    at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0

    at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean isAsync, Boolean anonymous) [0x00000] in <filename unknown>:0

    at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access) [0x00000] in <filename unknown>:0

    at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess)

    at Mono.CompilerServices.SymbolWriter.MonoSymbolWriter.WriteSymbolFile (Guid guid) [0x00000] in <filename unknown>:0

    at Mono.CSharp.SymbolWriter+SymbolWriterImpl.WriteSymbolFile () [0x00000] in <filename unknown>:0

    at Mono.CSharp.SymbolWriter.WriteSymbolFile () [0x00000] in <filename unknown>:0

    at Mono.CSharp.CodeGen.Save (System.String name, Boolean saveDebugInfo, Mono.CSharp.Report Report) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
     
  2. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    225
    Update: still happening. Windows 8, running Unity 5 in 64-bit editor. Randomly I get the above error and can't enter Play Mode nor can I build project.

    Anything I can do to fix this? Since I imported project with 64-bit editor, can I install 32-bit editor and still open this project? It works sporadically, then error comes up again. Somehow I randomly seem to be able to get rid of it then it comes back. I don't know what random reboot, restart Unity, mark TEMP folder as "read/write", or whatever I'm accidentally doing to appease the Unity gods. Currently it's a show-stopper and can't get it to run again. Have tried all random things I've been able to come up with and no luck this time.

    Help?
     
  3. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    225
    Maybe (probably?) a MonoDevelop thing? Was working fine all day until early this afternoon and I've done nothing but work with a few scripts all day. Nothing I have done with those scripts (that I'm aware of) should be causing this.
     
  4. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Try right clicking Unity and run as administrator. You may even want to go change the properties of the monodevelop executable to run ad administrator. It looks to me like a permissions issue. Since it appears random either it only happens when certain bits are compiled or your user profile in windows may be corrupt, but that's just a long shot guess at that point.
     
  5. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    225
    That didn't work either. Gr. Still locked out of building/play-mode. Just won't compile at all. Brand new laptop - clean, with absolutely nothing else installed. In fact, I just picked up this laptop to be my Unity development rig. The first thing I did was install Unity 5.0 - so I'd hope my user profile in windows isn't corrupt.

    Could this be a Windows 8.1 thing? Argh. Do I maybe re-install Unity 5.0? I've heard that seems to work for some of the bugs people have out there. Well... I'll try that and get back with results - in case others have same issue.
     
  6. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    I've built with unity 5 in both windows 8.1 and windows 10 ctp. One way to test the corrupt profile issue is to just create another user on your laptop and try to do a build with the new user account and see if that works.
     
  7. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    225
    Well, Dustin - it did seem to work at first! I created a new user on my Windows 8 laptop, and opened project from that new account, and lo-and-behold: it worked!!!
    It stayed working for a couple days in fact.

    Then, just now, I updated an Asset from the Asset Store... Is that broken now? It's not showing assets that there are updates to. I only updated an asset (had to search for it in my asset list, since there is no longer an indication of assets with updates... just reiterating that out of frustration...). BTW: it was TNET...

    Anyway, I updated it, and Unity 5 asked if I wanted to update the files to new API. I clicked yes, of course, because if I don't, the asset won't work, of course.

    After that update process... BROKEN again, and I get the errors above. Now I'll waste another few days trying to figure this out again - too many wasted days on this.

    So, to Dustin: thank you for the advice - it did actually seem to work (how, I don't know)
    To anyone else out there with this problem: still no fix. Though it seems updating Assets to new API, that is, if you can find which have updates on the Asset Store - seems to break projects and make them un-runnable, and un-compilable, with no actual error message that points to where the problem is or how to fix it.

    Can't really fill out a bug report because... I don't know what the bug IS.

    ARGH.
     
  8. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    225
    Again, error I get is:

    All compiler errors have to be fixed before you can enter playmode!

    And error comes out in one log entry as below:

    Unhandled Exception: System.UnauthorizedAccessException: Access to the path "C:\UNITY__Cor3volution\Temp\Assembly-CSharp.dll.mdb" is denied.

    at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0

    at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean isAsync, Boolean anonymous) [0x00000] in <filename unknown>:0

    at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access) [0x00000] in <filename unknown>:0

    at Mono.CompilerServices.SymbolWriter.MonoSymbolWriter.WriteSymbolFile (Guid guid) [0x00000] in <filename unknown>:0

    at Mono.CSharp.SymbolWriter+SymbolWriterImpl.WriteSymbolFile () [0x00000] in <filename unknown>:0

    at Mono.CSharp.SymbolWriter.WriteSymbolFile () [0x00000] in <filename unknown>:0

    at Mono.CSharp.CodeGen.Save (System.String name, Boolean saveDebugInfo, Mono.CSharp.Report Report) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0

    at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
     
  9. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Can you check to see if that file is marked as read-only? Also, try renaming it and see what happens. Almost seems like that file isn't getting cleaned up and can't be overwritten.
     
  10. stevekennedy

    stevekennedy

    Joined:
    Dec 20, 2014
    Posts:
    2
    I have a new ASUS ROG laptop with Win 8.1 and I get essentially the same problem. System.UnauthorizedAccessException on Assembly-CSharp.dll.mdb. I created a test project and made a very basic script, and 50% of the time, I get this error right away.
     
  11. danreid70

    danreid70

    Joined:
    Aug 28, 2010
    Posts:
    225
    Finally getting back to this - sorry for the delay. I FINALLY figured it out. Unity is fine. Windows 8.1 is fine. The issue is the frikkin Anti-Virus software. Especially if it's brand new and you didn't get a chance to remove the cr@p anti-virus that comes pre-bundled, and install something that works well... (I won't plug AVG here. Really I won't...).

    Anyway: Remove or replace your Anti-Virus, and that dreaded error will magically go away! Worked for me! :)

    And to Dustin: Thank you for your help in this - your responses here proved to me yet again that the Unity community is the most forgiving and helpful group I've ever been part of on the world-wide-net... :)
     
    Dustin-Horne and stevekennedy like this.
  12. stevekennedy

    stevekennedy

    Joined:
    Dec 20, 2014
    Posts:
    2
    After dealing with this same issue, I can confirm that McAfee was the culprit... Thanks for the help.
     
  13. Kirlim

    Kirlim

    Joined:
    Aug 6, 2012
    Posts:
    126
    This might help someone else who's having the same problem when using unity with McAfee:
    - Turn off On-Access scan. Yeah, you paid for that, but that's life. Change your AV when your paid period ends.

    If that does not solve it, theres the annoying second option. Be sure that there are no actual scripts compile errors, and only the unauthorized access exception:
    - Find any C# script in your project. Right click, then go "reimport" (DO NOT press reimport all!!!!). See Unity compiling again and probably fail. Try a few dozens of times, it'll eventually compile.

    Sometimes right click, reimport, won't trigger a recompile. Close Unity. Open Unity. Reimport fest.

    mcaffee.png

    From the picture, you can see that sometimes the exception disguises itself as another warning (but with the error icon)

    When building:
    - Configure everything so that you can build by hitting Ctrl+B. Hit ctrl + b until it eventually compiles. I assure you, eventually it will.

    Best solution:
    Uninstall McAfee.

    My thoughts on this (just theory):
    Mono recreates/changes/whatever the dll when building, immediately triggering the on-access scan of the antivirus. However, if mono is fast enough, it will try to access the dll before the av has finished scanning it, resulting in the exception. When reimporting a C# and triggering a recompile, OS scheduling might happen in a way that Mono will try to access the dll after the on-access scanning has finished, thus allowing you to be happy until the next code change, that'll be likely in less than 5 minutes.

    Opening Unity, Mono as admnistrator does not solve the problem. Not for me.
     
  14. Pyronide

    Pyronide

    Joined:
    Jun 7, 2014
    Posts:
    56
    ReImporting worked wonders for me, I had been having this issue for only a couple hours, but this fixed it. Thanks a lot!
     
  15. Kirlim

    Kirlim

    Joined:
    Aug 6, 2012
    Posts:
    126
    Recently, I've managed to somewhat configure McAfee (if you're using it) to ignore the .dll and .mdb files. If you try to do it, you'll notice that Unity deletes the file after the UnauthorizedAccessException, making it tricky to ignore the files. But it turns out that if you put the 'unauthorized access' files manually in the temp folder (when Unity is open, the folder is created), you can set up McAfee to ignore those files. Even if they are later removed and recreated, the ignore settings will continue existing and working.

    You can create dummy empty files there, as long as their name and extension are correct, it'll work,

    Downside is that you'll have to do this again and again for each different project that you get tired of right-click -> reimport.

    This might work for other AV with real time scan, as well.
     
  16. Pyronide

    Pyronide

    Joined:
    Jun 7, 2014
    Posts:
    56
    I simply right click and reimport every time, it hasn't happened a lot so its working for me now
     
  17. Lockthav

    Lockthav

    Joined:
    Dec 6, 2018
    Posts:
    6
    For me works right-clicking the file (in the explorer) > Properties > General > Attributes > Uncheck "Read-only"
     
    bruno1308 likes this.