Here is my code to retrieve a class from a different solution (both solutions are in the same folder) using an XML file:
var xml = XElement.Load("settings.xml");
var query = xml.Elements();
foreach (var XMLProtocol in query)
{
string NameSpace = XMLProtocol.Element("NameSpace").Value;
string ClassName = XMLProtocol.Element("ClassName").Value;
string FrequencyType = XMLProtocol.Element("FrequencyType").Value;
string FrequencyValue = XMLProtocol.Element("FrequencyValue").Value;
string path = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
System.Reflection.Assembly assembly = Assembly.LoadFrom(path + "../../" + NameSpace + "\\bin\\Debug\\" + NameSpace + ".dll");
System.Type type = assembly.GetType(NameSpace + '.' + ClassName);
Protocol protocol = new Protocol((IProtocol)Activator.CreateInstance(type), Convert.ToInt64(int.Parse(FrequencyValue) * GetFrequencyTypeMultiplier(FrequencyType)));
this.Add(protocol);
}
Execute();
This is the XML:
<Protocols>
<Protocol>
<NameSpace>ClassTest</NameSpace>
<ClassName>Class1</ClassName>
<FrequencyType>Minute</FrequencyType>
<FrequencyValue>20</FrequencyValue>
</Protocol>
</Protocols>
Is there a way to retrieve the assembly without having to "hardcode" the path to the DLL? What is the best practice for that scenario?