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

If you’re developing an assembly, placing it in the global assembly cache, and testing it from another application you probably want to keep making changes to the assembly, but don’t necessarily want to keep upping the version number (which means you will have to constantly change the reference in the testing application).

When dragging the assembly into c:\windows\assembly you may receive the error message

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

Even after deleting the existing file from the GAC you can still receive this error. What you need to do is go back to the good old command prompt. Click Start – Run and enter cmd.

Navigate to the directory where your assembly is stored

cd c:\windows\assembly\GAC_MSIL\assemblyname\
From here, you will see a directory for each version of the assembly. Inside that directory lies the actual dll. You need to remove the dll as well as the directory.
cd 1.1.0.1etc
rm myfile.dll
cd ..
rmdir 1.1.0.1etc

I found that when I deleted the assembly from windows, it removed the file but not the directory. Removing the directory from the command prompt resolved the problem and allowed me to drag my new assembly back in again.

In all honesty, you’re better off upping the version number for every change as this is more correct (and the way the GAC is intended to work), but if you do encounter the problem, then the above is the solution.

Advertisements

About Adam David Collings

Adam Collings is a writer of speculative fiction who works as a software engineer during the day. He lives in Tasmania, Australia with his wife and two children. Adam is currently working on a science fiction novel.
This entry was posted in Programming. Bookmark the permalink.

2 Responses to Cannot create/shadow copy “File Name” when that file already exists

  1. Javi says:

    Thank you very much! Our web developer is a real assholole and drives us crazy when a a patch includes changing dlls. Yoour post has been of great help, as was imposible ti install the new one in GAC. Deleting the dir has been the solution. Many thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s