Retrieving Assembly without DLL 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:



&lt;Protocols&gt;
  &lt;Protocol&gt;
    &lt;NameSpace&gt;ClassTest&lt;/NameSpace&gt;
    &lt;ClassName&gt;Class1&lt;/ClassName&gt;
    &lt;FrequencyType&gt;Minute&lt;/FrequencyType&gt;
    &lt;FrequencyValue&gt;20&lt;/FrequencyValue&gt;
  &lt;/Protocol&gt;
&lt;/Protocols&gt;


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?
Although this feels very "examplish", here are my thoughts:

Personally, I would rethink how you handle paths currently. As it stands, the directory structure must be very specific: you are provided with some "root" folder, and in that folder you have subfolders, each named after the namespace of the library within it, then a bin folder, then a Debug folder, so an example would be:


C:\Projects\Project1\bin\Debug\Project1.dll
C:\Projects\Project2\bin\Debug\Project2.dll
C:\Projects\ClassTest\bin\Debug\ClassTest.dll
et. al.



If you just wanted to drop a bunch of files in one folder, it's currently not possible.

Why don't you, instead, add the path as a line in the XML file?

&lt;Protocols&gt;
  &lt;Protocol&gt;
    &lt;NameSpace&gt;ClassTest&lt;/NameSpace&gt;
    &lt;ClassName&gt;Class1&lt;/ClassName&gt;
    &lt;FrequencyType&gt;Minute&lt;/FrequencyType&gt;
    &lt;FrequencyValue&gt;20&lt;/FrequencyValue&gt;
    &lt;FolderPath&gt;../../ClassTest/bin/Debug/&lt;/FolderPath&gt;
  &lt;/Protocol&gt;
&lt;/Protocols&gt;


The nicety of this is that you can now put your DLL's anywhere. You can use relative, absolute and virtual paths, and you can make them much more dynamic.

C:\Projects\Project1\bin\Debug\Project1.dll
C:\Projects\Project2\bin\Release\Project2.dll
C:\Dean Martin\ClassTest.dll
et. al.


This also means, that if you wish to use the release version of Project1, but the debug version of Project2, you can! Just include the appropriate path name!

This is generally the best-practice for this situation, as the "location" of a DLL file is a configuration aspect, rather than a programme aspect. Only in certain situations (with things like dynamic plugins) would you use a hardcoded (absolute, virtual, or relative: any of the three) path to get to the DLL's. And that would typically be something like Plugins\.



On a separate topic: I would recommend you use the @ prefix for your path strings, to be able to omit escapes:

System.Reflection.Assembly assembly = Assembly.LoadFrom(path + "../../" + NameSpace + @"\bin\Debug\" + NameSpace + ".dll");


This tends to make it more readable. Of course, if you move the file paths to the XML, it won't be a problem. :)