System.Type.GetType() doesn't work on WEBGL

Trying to get type from running assembly by full qualified type name:

var dataType = Type.GetType(typeName);
if (dataType == null)
{
     throw new NullReferenceException("unknown type: " + typeName);
}

It works fine when show exceptions option (in project settings) is setted to “Full” but don’t work when exceptions disabled. Is there any way to get type by name or I need to map types manual for compile time linkage?

For WebGL, the correct behavior of Type.GetType does require exception support to be enabled.

In order for System.Type.GetType(string) to work, we need to know something about the calling assembly to look for the type. In order to traverse the call stack to find the calling method (and therefore the calling assembly), we need call stack information. By default, call stack information is not generated for WebGL builds unless exception support is enabled, as it takes up some space and time. So without call stack information, we cannot support System.Type.GetType(string) correctly.

You can help WebGL though by telling it which assembly to use to find the type, then things work well. If you know the name of the assembly, you can also do something like this:

Assembly.Load("Assembly-CSharp").GetType("TestClass");

If you don’t know the assembly name, you will need to perform some manual step to make this work.