NotSupportedException for Assembly.GetExportedTypes

Issue #197 wontfix
Former user created an issue

I have a class in my project which is used to find all classes or interfaces that derive from a given type.

If Odin is present in the Unity project, using this class to find derived classes becomes impossible because as soon as Assembly.GetExportedTypes gets called, a NotSupportedException gets thrown:

NotSupportedException: The invoked member is not supported in a dynamic module. System.Reflection.Emit.AssemblyBuilder.GetExportedTypes () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.cs:680)

Removing Odin from the project fixes the issue.

The exception is thrown at line 39 of the attached document.

Comments (2)

  1. Tor Esa Vestergaard

    This isn't something we can do anything about, unfortunately - Odin uses dynamic assemblies to emit code so that reflection can be avoided. Without this, Odin would be very slow indeed.

    What you should do is, in your code, check if the assemblies you're calling GetExportedTypes on derive from System.Reflection.Emit.AssemblyBuilder - and if they do, skip them.

    foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
    {
        if (assembly is System.Reflection.Emit.AssemblyBuilder) continue;
    
        var types = assembly.GetExportedTypes();
        // etc...
    }
    
  2. Log in to comment