I am trying to run a test using NUnitEngine. But, it gives me FileNotFoundException: Could not load file or assembly. How to fix this?

Viewed 1166

I am reading a set of tests from an NUnit test dll file. I am reading it using System.Reflection. Then I am trying to run a test inside that dll using NUnitEngine.

But, while doing "runner.Run", NUnitEngine throws the following exception FileNotFoundException: Could not load file or assembly.

I have checked the path. It is correct. Can anybody please tell what could be the issue here ? My code is written in C#. I am using .NET Core 3.1

This is my code:

using System.IO;
using System.Reflection;
using NUnit.Framework;
using NUnit.Engine;
using System.Xml;

namespace MyNameSpace
{
  public class MyClass
  {

    public void RunTest()
    {
         // set up the options
         string path 
     ="C:/Practice_Code/NUnitTestDemo/bin/Debug/netcoreapp3.1/NUnitTestDemo.dll";

        TestPackage package = new TestPackage(path);

        // prepare the engine
        ITestEngine engine = TestEngineActivator.CreateInstance();
        var _filterService = engine.Services.GetService<ITestFilterService>();
        ITestFilterBuilder builder = _filterService.GetTestFilterBuilder();
        TestFilter emptyFilter = builder.GetFilter();

     using (ITestRunner runner = engine.GetRunner(package))
     {
 // execute the tests            
 XmlNode result = runner.Run(null, emptyFilter); //this line throws the exception
         System.Console.WriteLine("Test Result:");
         System.Console.WriteLine("----------------------------");
         System.Console.WriteLine(result.InnerXml.ToString());
      }
   }//METHOD RunTest ENDS

  }//CLASS MyClass ENDS

}//NAME-SPACE MyNameSpace ENDS

Here is the exception details:

NUnit.Engine.NUnitEngineException: 'An exception occurred in the driver while loading tests.'

Inner Exception FileNotFoundException: Could not load file or assembly 'NUnitTestDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

1 Answers
Related