0

From time to time, when I try to import, build or just compile, randomly Unity says that an:

IOException Sharing violation

I did a small research, but all the answers point to that error, when executing the code, not just build, and I say that is Random because It happens from time to time and every time the .dll in the Library folder that is marked in the Error, is completely different.

  • 3
    If you have antivirus software running that does real-time scanning it can interfere with things and cause issues like this. You could try excluding or whitelisting your project directory tree. – Retired Ninja Dec 24 '21 at 00:00
  • 2
    The first thing I did, whitelist, Unity, Rider as editor, and my repository folder. – Victor Cortes Dec 24 '21 at 00:41
  • 3
    ...adding to the fine tips above, make sure your code including your Unity project **isn't** stored on _file hosting services_ like _OneDrive_ or _DropBox_. Such apps don't like multiple edits within a short time period. –  Dec 24 '21 at 03:08
  • 1
    Yeah as others already hinted: This basically means some other application is accessing/locking the file(s) at the same time as Unity .. to extend the list of possibilities .. if you are using Git make sure the Library folder is excluded from version control! And GUIs like e.g. SourceTree loves to do that trick and lock your files while scanning so again, make sure that anything built related isn't in version control – derHugo Dec 24 '21 at 05:35
  • I recently bought a new SSD for storage, I just formatted it with the basic windows options, is possible that I misconfigured something? that SSD is where I keep the project. – Victor Cortes Dec 24 '21 at 18:42

2 Answers2

2

As some of the comments said, the error stopped appearing once I disabled the "Ransom/Encryption Protection" from my Antivirus (In this case Kaspersky) and also disabled it in the Windows options.

1

This can also happen, if a program interfers with itself in anyway, for example by having several projects run in parallel or a crashed instance holding onto a handle. Other candidates for handles might be Editors, other Background processes getting handles (e.g. thumbnail generators etc.).

Debugging should happen with a system tool to look at handles. Under windows for example ProcessExplorer(https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer) or Handle (https://learn.microsoft.com/en-us/sysinternals/downloads/handle). Set a breakpoint and then look at what caused the sharing violation.

Prerequisit is a clean software, meaning your own opened handles should be closed once they go out of scope. Some languages provide constructs for that, for example C#s using. Use them to preven dangling buffers.