I have a Unity project that when building to WebGL produces the following error:
Error: IL2CPP error for type 'System.Net.WebHeaderCollection/RfcChar' in assembly 'C:\PathToProject\Library\Bee\artifacts\WebGL\ManagedStripped\System.dll'
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
This only happens with one project. I see that there are other WebGL and IL2CPP issues posted, but they’re all different and none of them seem to have answers.
I have the same Issue. My project works building for ios, but when trying to build for webgl I get the error:
Error: IL2CPP error for type 'System.Net.WebHeaderCollection/RfcChar' in assembly '/Users/jasonraiti/project/Library/Bee/artifacts/WebGL/ManagedStripped/System.dll'
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
I had the same error, the project was building to WebGL fine, then stopped. Not sure what changed.
I removed parts of the project until it worked.
Turned out this bit caused it to fail to build to WebGL (ran within Unity fine)
Dictionary<string, string> requestBody = new Dictionary<string, string>()
{
{"state", "COMPLETED" }
};
// Serialize body as a Json string
string requestBodyString = JsonConvert.SerializeObject(requestBody);
This relied on
using System.Collections.Generic;
using Newtonsoft.Json;
I’m guessing it was something to do with Newtonsoft.Json, not sure of the best way to handle JSON in Unity so I just swapped out that section for a string to avoid needing that library.