Cannot create/shadow copy 'File Name' when that file already exists

The two common errors are

  1. Cannot create/shadow copy 'File Name' when that file already exists.

    Usually get this message usually when in a debug/edit/debug cycle after successfully building a C# solution and pressing F5 to debug it.

    Exception Details: System.IO.FileLoadException: Cannot create/shadow copy 'File Name' when that file already exists.

    If you wait a few moments before pressing F5 after a build, ASP.NET seems to have the time to complete whatever it needs to do. This is running Visual Studio 2005/ASP.NET on localhost.

  2. Unable to copy file obj\Debug\xyz.dll to bin\Debug\xyz.dll. The process cannot access the file bin\Debug\xyz.dll because it is being used by another process.

    Workarounds

    The best solution is to do the following, since VS basically locks the file and you cannot use third party resources to unlock it. Just use VS! In the Properties of a project in your IDE you have Build Events. Basically, you can write scripts during pre and post builds of a project. Add these lines in the pre-build event command line, which basically unlocks the DLL within Visual Studio.

     IF EXIST $(TargetPath).LOCKED  (del $(TargetPath).LOCKED)
      ELSE (IF EXIST $(TargetPath) (move $(TargetPath) $(TargetPath).LOCKED))

    Re-compiled and your unable to copy DLL error will not occur.

    More workarounds can be found on:

    http://www.connect.microsoft.com/VisualStudio/feedback/Workaround.aspx?FeedbackID=227522

Published 09 June 08 02:34 by Tom

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# ASP.NET Debugging : Cannot create/shadow copy 'File Name' when that file already exists said on June 9, 2008 5:54 PM:

PingBack from http://blogs.msdn.com/tom/archive/2008/06/09/cannot-create-shadow-copy-file-name-when-that-file-already-exists.aspx

# SVK said on June 1, 2009 3:08 AM:

in projects i clicked properties wherein i got a window iwth application , compiler etc

where do i write the above code lines inthe application

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

Search

This Blog

Syndication

Page view tracker