.Net file locking on compile

I kept on getting a problem whereby on trying to recompile a project in Visual Studio a dll assembly would be locked when I loaded the project up in a browser with a message such as:

Cannot copy assembly […] to file [..].dll. The process cannot access the file because it is being used by another process.

With a note that the error was something around:

Which wasn’t very helpful. Googling for the error message didn’t help much as there were all kinds of reasons for files being locked, but Googling for asp.net compile file locking did and I was lead to
this page which explains it.

I tried various ‘fixes’ of my own, such as rebuilding the entire solution, starting and stopping IIS through services, and sometimes it seemed to work and sometimes it didn’t. It was very bizarre and very annoying, but the file lock was starting to cause me real problems.

The solution

It was quite easy: disable the Indexing Service from the Services list. Apparently the indexing service was locking the file and it would be released after ‘a bit of time’, which was why my random attempts at fixes sometimes seemed to work, and sometimes didn’t.

Microsoft: sometimes, I really hate you.

Preventing compiled dll’s from being locked in Visual Studio.

Leave a Reply

Your email address will not be published. Required fields are marked *