ASP.Net cannot create/shadow copy
Asked Answered
H

11

41

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.

Hecker answered 17/6, 2009 at 13:58 Comment(4)
I'm repeatedly getting this error and I'm surprised Microsoft still have not fixed this.Cupriferous
we're actively working on this now. Given it's really hard to reproduce, it makes fixing the problem more difficult.Genetic
I've resubmitted the connect bug, just so it can be tracked by MS customers. connect.microsoft.com/VisualStudio/feedback/details/786247/…Artful
@Genetic - "really hard to reproduce"? it happens all the time (especially when using IIS Express), look at the views number of this post.Songstress
T
23

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).

Tinney answered 13/10, 2009 at 4:56 Comment(2)
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)Schaffel
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.Nestornestorian
E
39

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

Estienne answered 17/6, 2013 at 10:40 Comment(3)
it worked because the main reason for this issue is trying to access the webpage before the build process is finished in VS.Puparium
That's interesting, Zafar. Do you have any more information on that? This bug drives me crazy sometimes!Estienne
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.Puparium
T
23

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).

Tinney answered 13/10, 2009 at 4:56 Comment(2)
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)Schaffel
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.Nestornestorian
H
5

Just restart Visual studio, that worked for me.

Hawaiian answered 14/3, 2014 at 8:9 Comment(0)
P
1

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

Petulia answered 6/11, 2012 at 14:48 Comment(0)
M
1

In my situation only iisreset worked.

Milled answered 25/4, 2013 at 7:38 Comment(0)
C
1

I was getting the same issue, by placing this code in a web.config in <system.web> section it worked fine for me.

<hostingEnvironment shadowCopyBinAssemblies="false" />
Chiquita answered 21/3, 2015 at 21:34 Comment(0)
G
0

I was getting this issue frequently when working with an imported DLL which we created.

Attempts to stop is happening failed, and even introduced different problems, but whenever it occurred I would just do a rebuild solution and the problem would immediately disappear for that build.

Also, I haven't seen the problem since working on Visual Studio 2002. 2008 does not have this issue that I know of, neither does 2005. Are you using an older VS?

Gombroon answered 18/6, 2009 at 1:6 Comment(3)
ok, nothing to do with version then. If you do a rebuild solution does your application run?Gombroon
Yes, I "clean" the solution, rebuild, and work for 10-20 minutes. Then I get the error again and repeat.Hecker
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))Apthorp
K
0

GO to the design mode and then right click and hit view in browser, the issue will go away Anil Madan

Kirovabad answered 6/2, 2013 at 15:16 Comment(1)
Which works exactly the same as go smoke a cigarette and the issue will go awayGenetic
D
0

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-compile and your unable to copy DLL error will not occur.

Deboer answered 12/3, 2013 at 21:49 Comment(0)
O
0

If you use Entity Framework:

Error Message: "Cannot create/shadow copy '' when that file already exists."

Solution: "Wait a few seconds and refresh the page."

For more information please visit: Advanced Entity Framework 6 Scenarios for an MVC 5 Web Application (12 of 12)

Odele answered 13/3, 2015 at 11:25 Comment(0)
C
0

You just Refresh (F5) your page.

Choochoo answered 18/5, 2016 at 5:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.