Mehdi LAMRANI
Mehdi LAMRANI

Reputation: 11597

Using Reflection when an assembly contains types referencing another assembly

I am getting a ReflectionTypeLoadException from the following code :

var myAssembly = Assembly.LoadFrom(myDLL);    
var types = myAssembly.GetTypes())

myDLL references a class in another file in an other assembly ("myDependency.dll")
I made sure that this file resides in the application directory and also in the same folder as "myDLL" file.

How to be able to load myDLL properly in this case ?

Upvotes: 1

Views: 117

Answers (3)

Mehdi LAMRANI
Mehdi LAMRANI

Reputation: 11597

Well I am proud to announce that I have spoiled my Friday night on some stupid "eye-persistence" phenomenon caused by Visual Studio 2010 (I guess). I Just Copied-Pasted my DependencyDLL project into a brand new assembly/project, deleted the old one, updated old reference to point to the new DependencyDLLNew, And Voilà : That did the trick. Problem solved. Thank to those who helped.

Upvotes: 0

Danny Varod
Danny Varod

Reputation: 18069

  1. Make sure all your assemblies (dlls and exes included referenced assemblies) are up to date (platform, configuration and version/build date) and in your exe's directory.

    Try deleting all the projects' OBJ and BIN directories prior to your build to help validate this.

  2. Make sure you do not have other versions in the GAC or a directory in the %PATH%.

Upvotes: 1

ossek
ossek

Reputation: 1648

I'd try calling:

AssemblyName[] referenced = myAssembly.GetReferencedAssemblies();

then iterate over the AssemblyName objects and attempt to load those, prior to calling myAssembly.GetTypes()

Upvotes: 1

Related Questions