ASP.Net cannot create/shadow copy

33,916

Solution 1

The following workarounds come from this now defunct connect issue:

  • add <hostingEnvironment shadowCopyBinAssemblies="false" /> to the <system.web> section of your web.config file.
  • Restart Cassini when you get the problem
  • If you get the error, stop the debugger, right click the solution and "clean solution". Hit F5 to restart debugger. This is really annoying as it has >50% fail rate for me and you would think that there should not be a manual option to CLEAN SOLUTION! This $1200 POS application should clean it for you automatically!
  • Here's another workaround that may be more appealing to some, courtesy of Gary Farr (http://blogs.claritycon.com/blogs/gary_farr/archive/2007/03/09/2888.aspx).
  • Add the following to your pre-build events:

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

  • A workaround that does the job for me is instead of using "Build" use "Build Solution"

  • After a successful build, I count to ten, then I refresh my webform.
  • I have found that by re-registering ASP.NET against IIS the problem "goes away" - I haven't had the problem since. You will need to run the following on the command line:
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i. This more than likely won't work for everyone - it's a complex problem.
  • restart VS.
  • When Cleaning the solution, a few warnings were issued about files that could not be deleted. These files had their read-only property set. After setting the property of these files to read/write, the problem was solved.
  • Restart IIS

EDIT: Items retrieved from an old version of the page (courtesy of archive.org).

Solution 2

Wait somewhere between 10-30 seconds and hit refresh. For some reason this always works for me.

Solution 3

Just restart Visual studio, that worked for me.

Solution 4

Open your project properties, open the Web tab and make sure the Enable Edit and Continue option is not checked.

Solution 5

In my situation only iisreset worked.

Share:
33,916
david.mchonechase
Author by

david.mchonechase

Updated on May 18, 2021

Comments

  • david.mchonechase
    david.mchonechase almost 3 years

    I get this error repeatedly when developing ASP.Net applications:

      Cannot create/shadow copy 'XXXXX' when that file already exists
    

    Where XXXXX is a random DLL. Typically the DLL is one of the DLLs from Microsoft's Enterprise Library, but it varies.

    It's really random, and it's very frustrating. I will go hours without getting the error, and then get this error every 10-20 minutes.

    I've seen several solutions. For instance, this question. I've tried using Clean Solution option, and I've also simply restarted my local IIS. However, it still occurs at the same random but persistent frequency.

    I've also seen many people mention using this option in the config file:

    <hostingEnvironment shadowCopyBinAssemblies="false" />
    

    However, others have mentioned it being problematic, and it should definitely not be used in production.

    So, should I just give up and try the shadowCopyBinAssemblies option? (And make sure not to copy this change to other environments.) Am I the only one who gets this issue that often?

    Note: I am using Visual Studio 2008.

    • Eric Lennartsson
      Eric Lennartsson almost 14 years
      I'm repeatedly getting this error and I'm surprised Microsoft still have not fixed this.
    • RickAndMSFT
      RickAndMSFT over 11 years
      we're actively working on this now. Given it's really hard to reproduce, it makes fixing the problem more difficult.
    • Luke Puplett
      Luke Puplett about 11 years
      I've resubmitted the connect bug, just so it can be tracked by MS customers. connect.microsoft.com/VisualStudio/feedback/details/786247/…
    • BornToCode
      BornToCode over 10 years
      @RickAndMSFT - "really hard to reproduce"? it happens all the time (especially when using IIS Express), look at the views number of this post.
  • CRice
    CRice almost 15 years
    ok, nothing to do with version then. If you do a rebuild solution does your application run?
  • david.mchonechase
    david.mchonechase almost 15 years
    Yes, I "clean" the solution, rebuild, and work for 10-20 minutes. Then I get the error again and repeat.
  • AlejandroR
    AlejandroR almost 15 years
    I got the same issue while working with DotNetNuke. It disappeared magically after fixing a wrong PortalAlias. Strange things happens. As an alternative to the hostingenviroment setting: Add this to the Pre-Build event command line: IF EXIST $(TargetPath).LOCKED (del $(TargetPath).LOCKED) ELSE (IF EXIST $(TargetPath) (move $(TargetPath) $(TargetPath).LOCKED))
  • Kirk Woll
    Kirk Woll about 13 years
    Thanks for the link, but took some sifting. The one that worked for me was "after a successful build, i count to ten, then i refresh my webform." (though I only counted to 2)
  • m-smith
    m-smith almost 12 years
    Best fix from that link for me was "restart IIS". I'm running local IIS instead of Cassini as my dev web server. Cheers. P.S. I'm using VS2010, so they still haven't fixed it.
  • RickAndMSFT
    RickAndMSFT over 11 years
    Which works exactly the same as go smoke a cigarette and the issue will go away
  • Zafar
    Zafar over 10 years
    it worked because the main reason for this issue is trying to access the webpage before the build process is finished in VS.
  • joshcomley
    joshcomley about 10 years
    That's interesting, Zafar. Do you have any more information on that? This bug drives me crazy sometimes!
  • Zafar
    Zafar about 10 years
    The only thing I know about this is - you get this error when you try to access a webpage before the dependent DLL files are finished to build. Well, that is not the only case for the error I think, but this one is most popular.