I am working on a project that serves as a robot tester, by crawling through a bunch of data files and running an application against those data files. This tester application is written in VB.Net, using .Net Framework 4.0. The application being tested is a VB.Net desktop application, but uses supporting components written in C++/CLI, C#, and VB.Net. All of the components of this project use .Net 4.0. The main VB.Net application uses Framework 4.5. The C++ component uses dependency injection to load a class that is defined in C#. The C# class implements an interface that is defined in the C++ component. Here is the C++ interface definition, inside of the CLICore namespace:
namespace CLICore { public interface class IConnGen { List<TCC::Conns::MomConn^>^ GenerateConns(TMainDocument^ document); }; public ref class ConnGen abstract sealed { private: static Func<TCC::Conns::IConnDesignProfile^, IConnGen^>^ _Factory; public: static property Func<TCC::Conns::IConnDesignProfile^, IConnGen^>^ Factory { Func<TCC::Conns::IConnDesignProfile^, IConnGen^>^ get() { return _Factory; } void set(Func<TCC::Conns::IConnDesignProfile^, IConnGen^>^ value) { _Factory = value; } } }; }
Here is a C# implementation of IConnGen, in the TCC.Conns namespace
namespace TCC.Conns
{
public abstract class ConnGenBase : CLICore.IConnGen { protected IConnDesignProfile DesignProfile { get; set; } protected ConnGenBase(IConnDesignProfile profile) { DesignProfile = profile; } public List<MomConn> GenerateConns(TMainDocument document) { List<MomConn> connList = new List<MomConn>(); connList.AddRange(GenRConns(document)); return connList; } }
}
Here is the C# definition of the IConnDesignProfile interface, in the TCC.Conns namespace:
public interface IConnDesignProfile { DesignProfileKey Key { get; set; } }
Here is the C# class definition for ConnDesignProfile:
namespace TCC.Conns { public static class ConnDesignProfile { public static Func<IConnDesignProfile> Factory { get; set; } } }
Here is the actual instantiation of an object that implements the IConnGen interface:
void DesignConns(TMainDocument^ mainDoc)
{TCC::Conns::IConnDesignProfile^ designprofile = TCC::Conns::ConnDesignProfile::Factory->Invoke();CLICore::IConnGen^ conngensvc = CLICore::ConnGen::Factory->Invoke(designprofile);
}
Here is the problem: All of this works fine, except when I load the DLL that creates TMainDocument through Reflection. Then, I get the following error when I try to execute the second of the two lines above:
"Could not load type 'CLICore.IConnGen' from assembly 'Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'."
Why can I instantiate an object that implements IConnGen when I load the TMainDocument via a direct reference, but not when I load it with Reflection?