views:

63

answers:

0

I am trying to load an assembly into memory and then instantiate types within that assembly. The objects are all of the same type (ITestMod). The following seems to work well:

 private void LoadTestAssembly(string assemblyName)
    {
        try
        {
            Assembly assembly = Assembly.LoadFrom(@".\testmods\" + assemblyName);
            Type type = assembly.GetType("TestModule.StressTestMod");
            currentTestMod = Activator.CreateInstance(type) as ITestMod;
        }
        catch(FileNotFoundException fnf)
        {
            MessageBox.Show("Could not find module: " + assemblyName, "Assembly Loading", MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
        }

    }

When I attempt to run a method of this obj I get a null reference pointer. However currentTestMod is not null. Any suggestions?

if (currentTestMod != null)
        {
            currentTestMod.RunTests(this); // Throws Exception
        }

The ITestMod interface:

public interface ITestMod
{
    void RunTests(HtmlTestForm parentForm);
}