Wednesday, 13 November 2013

Cannot create/shadow copy 'Autofac.Integration.Mvc' when that file already exists.


Exception


=== Pre-bind state information ===
LOG: User = Domain\Cpo
LOG: DisplayName = Autofac.Integration.Mvc
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Autofac.Integration.Mvc | Domain ID: 11
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///D:/WebUI/
LOG: Initial PrivatePath = D:\WebUI\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\WebUI\web.config
LOG: Using host configuration file: C:\Users\Cpo\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Cpo/AppData/Local/Temp/Temporary ASP.NET Files/root/5c8bbc72/8da9d219/Autofac.Integration.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Users/Cpo/AppData/Local/Temp/Temporary ASP.NET Files/root/5c8bbc72/8da9d219/Autofac.Integration.Mvc/Autofac.Integration.Mvc.DLL.
LOG: Attempting download of new URL file:///D:/WebUI/bin/Autofac.Integration.Mvc.DLL.
LOG: Using application configuration file: D:\WebUI\web.config
LOG: Using host configuration file: C:\Users\Cpo\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Autofac.Integration.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da
ERR: Failed to complete setup of assembly (hr = 0x800700b7). Probing terminated.

Fix 1


Clean your solution and restart your application.

Fix 2

The .Net Framework has a feature called Shadow Copy. Shadow copy is enabled on every appdomain created by ASP.NET by default. By default assemblies loaded will be copied to a shadow copy cache directory, and will be used from that location. Why does ASP.Net do this? So the original file is not locked and can be modified. An interesting error I have ran into intermittently when running ASP.Net apps with the debugger is ‘Cannot create/shadow copy when that file already exists‘ I’m still not sure why this happens only on occasion, as I can often clean my solution, then reload a web app and it will work fine then. But if you are getting it frequently enough for it to affect your work, you can add the following to your app’s web.config or the master .Net web.config:
<system.web>
   <hostingEnvironment shadowCopyBinAssemblies="false" />
</system.web>

Note: this fix is copied from: http://ranafaisal.wordpress.com/2008/03/25/cannot-createshadow-copy-when-that-file-already-exists/