Dennis Doomen
Dennis Doomen

Reputation: 8889

GetExportedTypes() on an assembly throws NotSupportedException

I'm having some serious troubles getting a Windows Phone 7.5 class library to load into the WP Unit Test Framework. It internally calls GetExportedTypes() on my assembly which throws a ReflectionTypeLoadException that doesn't contain any details. Its message is "ReflectionTypeLoadException" and its LoaderExceptions is null ("Could not evaluate expression"). The assembly is not using any 3rd party assemblies. If I create a separate WP7 app and do the same thing, I get the same results. I'm a very experienced Reflection user, but the lack of any detailed errors has brought my research to a complete halt. Just for completeness, it's the Windows Phone version of Fluent Assertions.

Upvotes: 3

Views: 354

Answers (2)

Dennis Doomen
Dennis Doomen

Reputation: 8889

I've found it! @GeertvanHorrik pointed me at a blog post he recently wrote. I was using an covariant interface (using the out parameter) which the runtime (!) doesn't support. Why the compiler does not protect me from that is a big mystery (and a huge disappointment) to me

Upvotes: 1

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174309

What about the Types array on the exception? Does it contain values? If so, does it also contain nulls? If so, you can find out which classes failed to load: You know all classes in the assembly and you know which classes loaded correctly. Those that are missing are the classes that couldn't be loaded. Maybe this info gives some clues.

This answer is based on the documentation, especially these bits:

From the Remarks of the LoaderExceptions property:

The LoaderExceptions property retrieves an array of type Exception that is parallel to the Types array. This array will contain null values whenever reflection cannot load a class.

And from the documentation of the Types property:

An array of type Type containing the classes that were defined in the module and loaded. This array can contain some null values.

Upvotes: 1

Related Questions