views:

95

answers:

2

Hi

I´m dynamically creating an instance of a class with reflection and this works fine, except when trying to do this through unit testing - I´m using the MS testing framework.
I get the familiar error of: "Could not load file or assembly 'Assy' or one of its dependencies. The system cannot find the file specified"
I have copied the dll into the bin\debug bin of the Unit test project - is this not the correct place to put it?

string assyName = "Go.Data.SqlServer";
string typeName = "GoMolaMola.Data.SqlServer.DataProviderFactory";

Assembly assy = Assembly.Load( assyName );
object o = assy.CreateInstance( typeName );

Any ideas? I'm new to unit testing and any help would be appreciated.

Thanks

A: 

For cases like this, when loading the DLL dynamically is needed from the Unit Testing, I have a post-build event that copies the DLL to that directory. I'd love to know if there's another way to do it. That was the only way that worked for me :(

To edit a Post-Build, right-click over the project, go to Build events, and place the copy, like this, in the Post-Build event command line:

copy $(TargetPath) "$(SolutionDir)yourDir\$(TargetFileName)"
Andrea
+4  A: 

The bin/Debug folder is not where the unit tests run. Visual Studio will copy the output of your unit test compilation to a TestResults folder (typically keeping the last five test runs, each with a timestamp embedded in the folder name) and run the unit tests there.

If you want the .DLL in that folder, either create a reference to the .DLL from your test project, or use the DeploymentItem attribute to make sure the item is copied to the test directory.

Randolpho
You are right, it's not run from the bin folder.I added a reference from the test project and that took care of that!Thanks for your help
iammaz