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
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.
I faced this problem too and none of the above answer worked for me :( 1. Adding reference to project doesn't work for me 2. Adding the DeploymentItem attribute also doesn't work 3. Adding the Post-Build command is also not possible in this case as Unit test engine is creating a new out directory each time with time stamp....and its searching that assembly in this new directory.
but I managed to solve this by enabling deployment and adding the specified file in Local Test Setting -->Deployment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With