<p>My application dynamically loads assemblies at runtime from specific subfolders. These assemblies are compiled with dependencies to other assemblies. The runtime trys to load these from the application directory. But I want to put them into the modules directory.</p>

<p>Is there a way to tell the runtime that the dlls are in a seperate subfolder?</p>

[{'answer_id': 22022, 'author': 'samjudson', 'author_id': 1908, 'author_profile': 'https://Stackoverflow.com/users/1908', 'pm_score': 2, 'selected': False, 'text': '<p>You can use the <code>&lt;probing&gt;</code> element in a manifest file to tell the Runtime to look in different directories for its assembly files.</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/823z9h8w.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/823z9h8w.aspx</a></p>\n\n<p>e.g.:</p>\n\n<pre><code>&lt;configuration&gt;\n &lt;runtime&gt;\n  &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;\n     &lt;probing privatePath="bin;bin2\\subbin;bin3"/&gt;\n  &lt;/assemblyBinding&gt;\n &lt;/runtime&gt;\n&lt;/configuration&gt;\n</code></pre>\n'}, {'answer_id': 22026, 'author': 'Shaun Austin', 'author_id': 1120, 'author_profile': 'https://Stackoverflow.com/users/1120', 'pm_score': 5, 'selected': True, 'text': "<p>One nice approach I've used lately is to add an event handler for the AppDomain's AssemblyResolve event.</p>\n\n<pre><code>AppDomain currentDomain = AppDomain.CurrentDomain;\ncurrentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);\n</code></pre>\n\n<p>Then in the event handler method you can load the assembly that was attempted to be resolved using one of the Assembly.Load, Assembly.LoadFrom overrides and return it from the method.</p>\n\n<p>EDIT:</p>\n\n<p>Based on your additional information I think using the technique above, specifically resolving the references to an assembly yourself is the only real approach that is going to work without restructuring your app. What it gives you is that the location of each and every assembly that the CLR fails to resolve can be determined and loaded by your code at runtime... I've used this in similar situations for both pluggable architectures and for an assembly reference integrity scanning tool.</p>\n"}, {'answer_id': 22029, 'author': 'jfs', 'author_id': 718, 'author_profile': 'https://Stackoverflow.com/users/718', 'pm_score': 1, 'selected': False, 'text': '<p>You can use the <code>&lt;codeBase&gt;</code> element found in the application configuration file. More information on "<a href="http://msdn.microsoft.com/en-us/library/15hyw9x3.aspx" rel="nofollow noreferrer">Locating the Assembly through Codebases or Probing</a>".</p>\n\n<blockquote>\n  <p>Well, the loaded assembly doesn\'t have\n  an application configuration file.</p>\n</blockquote>\n\n<p>Well if you know the specific folders at runtime you can use <a href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly.loadfrom.aspx" rel="nofollow noreferrer">Assembly.LoadFrom</a>. </p>\n'}]
['https://Stackoverflow.com/questions/22012', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2374/']