.Assembly / GetExportedTypes throws FileNotFoundException

c#, reflection

Solution

This doesn't exactly answer your question, but I just had a related problem to this and I thought I'd post some info to help others who may stumble across this as I did!

`Assembly` has

.LoadFile(string path)

and

.LoadFrom(string path)

`LoadFile` will throw a `FileNotFoundException` if loading the assembly from some remote (not the same as the executing dll) folder. You need to use `LoadFrom` as you do above ;)

Problem

If I run this code: ``` var myAsm = typeof(MyType).Assembly; var types = myAsm.GetExportedTypes(); ``` I get: ``` System.IO.FileNotFoundException : Could not load file or assembly .... ``` which lists a dependent assembly. However, if I do: ``` var myAsm = Assembly.LoadFrom(...); // DLL containing the same assembly as above var types = myAsm.GetExportedTypes(); ``` it works fine. I really would prefer the first technique, as it's cleaner... why should I have to load a DLL that is already loaded? Any advice?

Original source