Search code examples
c#reflectiontypeloadexception

ReflectionTypeLoadException: Type is attempting to implement an inaccessible interface


I'm using Assembly.GetTypes() for getting all types defined by in a plugin library (so I can instantiate plugin instances).

On a particular library, the method raise a ReflectionTypeLoadException, saying:

Type <Type> is attempting to implement an inaccessible interface

Googling it seems because the specific Type implements a non-public interface. And actually it is, but the Type is nested in another public class, declared as private.

How avoid this exception?

....

Made interface public the code works. Is it possible to define this strange behavior is a bug (in Assembly.GetTypes())? This imply that a library type cannot implement a protected interaface!


Solution

  • The problem was solved by removing the protected nested type from the public type.