Search code examples
visual-studio-2010process.net-assemblyfilelock

Assembly is being used by another process


I've upgraded a WCF project running 3.5 vs2008 to .net 4.0 vs2010 and run into a problem. When compiling from vs2010 an assembly in my service implementation project is locked by devenv.exe (note no debugging - only compiling). The assembly is released when vs2010 is restarted and can be compiled once, after each restart. What I've tried to far:

  1. Insert PreBuild event to unlock the assembly
  2. removed assembly version wild card
  3. Disabled source stepping
  4. stopped windows search
  5. stopped IIS
  6. quit vs2010, removed sln.suo and bin/obj folder
  7. Read blog and SO posts for 3 days now :)
  8. Removed all references from the service project and readded them

I've pretty much run out of ideas and it seems that Microsoft have no explaination for this an no fix. Any ideas would be greatly appreciated!

Error Message:

Unable to copy file ".....some path...\Debug\HelperLibrary.Service.dll" to "bin\Debug\HelperLibrary.Service.dll". The process cannot access the file 'bin\Debug\HelperLibrary.Service.dll' because it is being used by another process.

Bonus information: When compiling from prompt with msbuild, there's no problem. Only when compiling from vs2010. The old vs2008 solution of course still work.

Microsoft Ticket: https://connect.microsoft.com/VisualStudio/feedback/details/682485/use-of-testaccessor-and-impl-of-codeaccesssecurityattribute-locks-assembly


Solution

  • Ok, so my colleague gets back from vacation and said he bumped into this problem earlier :) It seems that root cause for the assembly to be locked (or held by the building process), is due to the use of testaccessors to test private methods, in combination of an implementation of CodeAccessSecurityAttribute. Note that this is not a problem in Visual studio 2008, but only in 2010 See another case here:

    http://social.microsoft.com/Forums/en/Offtopic/thread/41ceebce-1ecf-4962-86d0-e68050df4a99

    I've yet to find a solution for this, besides altering the private methods to public - I'll create a new post for this problem.