ASP.Net cannot create/shadow copy

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

Method 2

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:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_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).

Method 3

Just restart Visual studio, that worked for me.

Method 4

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

Method 5

In my situation only iisreset worked.

Method 6

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" />

Method 7

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?

Method 8

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

Method 9

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.

Method 10

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)

Method 11

You just Refresh (F5) your page.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x