3

I have an application that loads most of its dll's from a subfolder specified in the configuration (myapp.exe.config) file in the attribute

<probing privatePath="subdir"/> 

My question is: Can I load a dll (say mydll.dll) at runtime, using only its filename, if it the dll lives in the same subdirectory "subdir" specified in the probing path?

I tried Assembly.LoadFile("mydll.dll") but that won't search in "subdir".

Cristian Diaconescu
  • 34,633
  • 32
  • 143
  • 233

2 Answers2

4

Personally I don't really trust trust probe paths - dlls have always been a nightmare, and .net's done nothing to improve that situation. If you're going to use Assembly.Load anyway, and you know exactly where to look, why not just locate the dll for yourself and be sure that you load precisely what you want instead of letting .net decide something 6 years old from a dank corner of the LAN is much more exciting?

Jason Williams
  • 56,972
  • 11
  • 108
  • 137
1

You need not load the dll file, just use Type.GetType(typeName) to get your type, then use this type to instance your object

Bbants
  • 26
  • 1
  • 2
    You should be aware that you need the fully qualified name of the type in order for this solution to work correctly, see [http://msdn.microsoft.com/en-us/library/w3f99sx1.aspx](http://msdn.microsoft.com/en-us/library/w3f99sx1.aspx) – Peter Monks Mar 21 '12 at 17:31