- Home /
WebGL XML parsing error "InvalidOperationException"
"InvalidOperationException: The specified type was not recognized: name='DialogueObjective' namespace=", at <Objective xmlns=">"
I am using XMLSerializer to save and load data for a quest system. I am able to handle the extra types and the parsing works in all builds, except in WebGL. When I book up WebGL, I get this error. DialogueObjective is a derivative of the Objective class. Here is the XML line in question:
<Objective xsi:type="DialogueObjective">
Objectives are contained in a list inside of a class "Quest". Quest is serialized and Deserialized and handed an array of Types derived from Objective. This works in editor and all other build types, EXCEPT in WebGL
Here is the serialization code for Quest:
public static Quest SaveData(string path, Quest q = null){
if(q == null){
q = new Quest();
q.Objectives.Add(new InteractObjective());
}
XmlSerializer questSerializer = new XmlSerializer(typeof(Quest), GetClasses(typeof(Objective)).ToArray());
using(var stream = new FileStream(path, FileMode.Create)){
questSerializer.Serialize(stream,q);
}
return q;
}
public static List<System.Type> GetClasses(System.Type baseType){
return System.Reflection.Assembly.GetCallingAssembly().GetTypes().Where(type => type.IsSubclassOf(baseType)).ToList();
}
public static Quest Load(string data){
XmlSerializer serializer = new XmlSerializer(typeof(Quest), GetClasses(typeof(Objective)).ToArray());
return (Quest)serializer.Deserialize(new StringReader(data));
}
$$anonymous$$essing with it more, the error doesn't show up with Exception Handling turned to "Full" but the class type doesn't serialize correctly.
This thread might have gotten lost during the Answers server downtime.
Your answer
Follow this Question
Related Questions
XML Serialization not working on WebGL 0 Answers
Confusion with process of XML setup 0 Answers
Parse XML to Vector3 (and other objects you don't control) 0 Answers
unity and xml question 1 Answer