NotSupportedException: The called element is not supported in a dynamic module in C # Unity 5

This is for my graduation project. The idea behind the game in a nutshell is to help students practice programming by providing some interesting missions that require a C # code solution, like codingame.com, when the user produces correct output, the result is rendered in a Unity scene.

I am using a C # compiler plugin to compile user code at runtime Unity 5. Everything works fine (each scene itself starts playing the scene in the editor and stops it), but when I move from scene to next, this error occurs when I create code user C # at runtime (NotSupportedException: The called element is not supported in a dynamic module) (the error always increases in the second scene or in the next scene).

Mistake:

NotSupportedException: The invoked member is not supported in a dynamic module

      

Mistake

The line that produces the error:

this.assemblyReferences = domain.GetAssemblies().Select(a => a.Location).ToArray();

      

assemblyRefrences is an array of strings: string [] assemblyReferences;

this line is in a script called ScriptBundleLoader in its constructor

+3


source to share


1 answer


The error occurs because you are trying to get the location of the assembly in memory (the ones you created on the fly) and those assemblies are not located anywhere.

If you want to avoid this error, try something like this:

this.assemblyReferences = domain.GetAssemblies().Select(a => 
{ 
    try{ return a.Location; }catch{ return null; }

}).Where(s => s != null).ToArray();

      



EDIT:

As Jon Skeet pointed out, it can be used in place of IsDynamic instead of catching the exception:

this.assemblyReferences = domain.GetAssemblies()
    .Where(a => !a.IsDynamic)
    .Select(a => a.Location)
    .ToArray();

      

+2


source







All Articles