Resharper shadow copies assemblies before test runs

Resharper shadow copies assemblies before test runs


2 min read

While writing an XML parser I customised, my unit tests all failed with an error message along the lines of "Could not load file 'C:\Users[username]\AppData\Local\Temp[guid]\Data\test.xml' or one of its dependencies. The system cannot find the file specified.".

My test solution contains a folder Data in which I put a test.xml file that contains an example of the data I need to parse. This allows me to test both reading and parsing the file in a single test. The problem is that the test can't find the xml file on my laptop and on a colleagues laptop all tests are green.

So after a bit of googling, I found out that Resharper is doing some clever shenanigans. Resharper copies the assemblies to a test folder in the '~\AppData\Local\Temp[guid]\'. So if the tests run from that location, you won't see errors that the assemblies are in use by another process when you build the solution while tests are running.

To prevent Resharper from shadow copying the assemblies to the temporary location, open the Resharpers options, go to the Tools > Unit Tests page and under the Unit Test Runner chapter, disable the Shadow copy assemblies being tested.

In most test scenarios, this won't cause any problems and is a rather useful feature to have. Whenever this isn't convenient, I hope my bumbling around will save somebody else an hour of their time.