Search Issue Tracker
By Design
Votes
5
Found in
5.0.0b20
Issue ID
664765
Regression
Yes
Type.GetType() in WebGL does not match the output given in the editor
How to reproduce:
1. Open a new project
2. Create a script called "testGetType.cs" with the following code:
using UnityEngine;
using System;
public class RequestedClass {
//I'm a class!
}
public class testGetType : MonoBehaviour {
Type operatorType;
void Start () {
operatorType = Type.GetType("RequestedClass");
}
void OnGUI() {
GUILayout.Label ("Is the operator null? " + (operatorType == null));
GUILayout.Label ("What is the operator? " + operatorType);
}
}
3. Attach the script to any game object in the scene
4. Play the scene
- Note how the text shows that the operator type is not null, and that it is of the type RequestedClass.
5. Build to WebGL and run
- The text now shows that the operator type is null and does not return anything for the type.
A simple workaround would be to change the code at
operatorType = Type.GetType("RequestedClass");
to
operatorType = Assembly.Load("Assembly-CSharp").GetType("RequestedClass");
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Silent crash when loading profiler binary information file
- Crash on DispatchMessageW when using FolferBrowserDialog
- [iOS] The Texture is black when the ASTC 10x10 or 12x12 image format is selected
- The right side of the Inspector flickers when undocked and resized by dragging the left side of the Inspector
- The size of the main tab in the Inspector slightly changes when Inspector is focused and an Asset is selected in the Project window
mvm95
Apr 13, 2017 14:03
How can the workaround be applied to object.GetType(); ?
softaria
Mar 14, 2016 07:22
Would be great to create "WebGL limitations" section in the official documentation and describe these issues there. It would save us days.
Thank you
softaria
Mar 14, 2016 07:17
The similar problem appears also when you use:
var assembly = Assembly.GetExecutingAssembly();
IEnumerable<Type> assemblyTypes = assembly.GetTypes();
The types inside the list are somehow broken in this case. E.g. when you call
Attribute at = type.GetTypeAttribute<Attribute>();
on type which has [Attribute] attribute, you will get null.
As the original bug it can be fixed by replacing
var assembly = Assembly.GetExecutingAssembly();
with
var assembly = Assembly.Load("Assembly-CSharp");