Exception caught when deserializing a .xml: Failed to load configuration section for dataContractSerializer
TLDR: I'm building to my Oculus Quest 2 and received an error: "Failed to load configuration section for dataContractSerializer" I found a site that said to change my api compatibility but Unity won't let me switch it.
I'm currently working on building a game to the Oculus Quest 2. It builds and runs fine, but I'm having problems with deserializing data from a .xml file into the game. I'm using Application.streamingAssetsPath and UnityWebRequest because of the whole .jar problems with androids, and I'm temporarily using the same method in the Unity Editor for debugging purposes. It works fine in the editor but gives an error on the Quest 2. Here is my code:
DataContractSerializer serializer = new DataContractSerializer(typeof(CoreData));
XmlDictionaryReader reader = null;
CoreData coreData = null;
UnityWebRequest webRequest = null;
try
{
webRequest = UnityWebRequest.Get(filePath);
webRequest.SendWebRequest();
while (!webRequest.downloadHandler.isDone) { }
Console.WriteLine(webRequest.downloadHandler.text); //prints out the text in the .xml
//deserialize
reader = XmlDictionaryReader.CreateTextReader(webRequest.downloadHandler.data, new XmlDictionaryReaderQuotas());
coreData = serializer.ReadObject(reader, true) as CoreData;
if (coreData != null)
outCoreObj.SetSerializedData(coreData);
}
//catch and finally statement
I'm using the command prompt with adb for debugging and it's able to print out the text inside of the xml file, but the catch block is still printing out this error when it tries to deserialize the data from the web request
Failed to load configuration section for dataContractSerializer
I'm honestly at a loss at this point. I know there's nothing wrong with the file path, I know it's retrieving the data from the xml file in the web request, but it catches an error on the "coreData = serializer.ReadObject(reader, true) as CoreData" line (which could also be a problem from the line above it).
The only answer I've been able to find is this. Their error looks slightly different, but I tried switching my API compatibility to 2.0 from 4.x and adding the link.xml anyways, but when I tried to switch the api compatibility, it didn't work. Basically, I clicked 2.0, it started loading, then once it finished loading it switched back to 4.x. I don't know anything about .NET stuff though so maybe there's an obvious reason for that.
If anyone could provide any advice on how to either get rid of this error or switch my API compatibility so I can test that method, I would be extremely thankful. I've been stuck on this problem for a while now.