Build/Test Issues

File Issue - Incorrect Path

Started by ahasnaini on 5,869 views

As part of the tests I am creating a file and using it, when running the tests using ReSharper it works fine, when I use NCrunch I get
System.IO.FileNotFoundException : Could not find file 'C:\Users\xxx\AppData\Local\NCrunch\1217

I am generating a file in this location AppDomain.CurrentDomain.BaseDirectory, it seems like it doesn't work with NCrunch as the directory is different, i can see file is generated in the debug folder.
Hi,

Is the file being generated in a project that is referenced by the project containing the code that is using it?

If so, you need to be aware of how NCrunch wires together application domains across its workspaces. See http://www.ncrunch.net/documentation/considerations-and-constraints_assembly-colocation-assumptions.

Under NCrunch, the AppDomain.CurrentDomain.BaseDirectory will be set to the output directory of the test assembly. If you're looking for the output directory of one of your production assemblies, the safer way to locate this is by instead using reflection to find it. For example: typeof(TypeWithinAssembly).Assembly.Location

Turning on the 'Copy referenced assemblies to workspace' setting for the projects involved will often solve these problems, but this comes with a significant performance cost.
Turning on the 'Copy referenced assemblies to workspace', I don't think this will resolve the problem as the test do run, but test generate a csv which is checked at the base directory, but as you said, I will use dll location and instead of the base and see if that resolves the issue

Post a reply

Log in to reply.