Stack Exchange
nunit version 3 not able to test code involving dynamic generation of assemblies
Scenario:  As part of the logic, the system generates a dynamic assembly as follows.
CompilerParameters cp = new CompilerParameters();

cp.GenerateExecutable = false;
cp.GenerateInMemory = true;

cp.TreatWarningsAsErrors = false;
cp.ReferencedAssemblies.Add("Employee.dll");
cp.ReferencedAssemblies.Add("Person.dll");

CompilerResults cr = provider.CompileAssemblyFromSource(cp, "someCode");
if (cr.Errors.Count > 0)
{..}

I open the Unit Test Assembly in NUnit-Gui-0.6.0 and test a method which ends up calling the above code as part of the business logic.
Issue:  Above Error Count is greater than 0 and has the following messages:
error CS0006: Metadata file 'Person.dll' could not be found
error CS0006: Metadata file 'Employee.dll' could not be found

I have verified that these assemblies are present in the bin directory along with the Unit Test DLL.  This code works in regular application workflow but not in NUnit 3.*.
Environment Details: VS 2017.  Unit Test DLL and Application DLLs are full .NET Framework 4.7.1.
Not sure if this is a bug in NUnit 3.* or an application issue.
Regards,
Iftikhar.

Which configuration mode do you use when compiling the unit test project? When you select "Debug" configuration mode, dll files get output into bin\Debug folder as a default. Since you said your assemblies are in bin folder, please check if you did not placing your assembly in bin\Debug folder.

I have tried both debug and release modes.  I don't think that is issue because other unit tests which doesn't involve dynamic compilation passes without any errors.  I would suspect we would have receive "Unable to find assembly" in the scenario you mentioned.
