Code below generates very strange TypeLoadException. If you comment foreach call in BogusClass everything will work fine.
Note that BogusClass.BogusFunct() method neither called or referenced in any place. If you just declare this class with access to HashSet or Dictionary, you’ll break program. Also not all method calls of HashSet leads to error.
it’s all very mysterious.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Test : MonoBehaviour {
void Start () {
Debug.Log("Started");
try
{
TestClass[] _arr = new TestClass[]
{
TestClass.A,
TestClass.B,
};
}
catch (System.Exception e)
{
//TypeLoadException
throw e;
}
}
void Update () {
}
}
public class BogusClass
{
private readonly System.Collections.Generic.HashSet<int> mContainer = new System.Collections.Generic.HashSet<int>();
protected Dictionary<int, string> dict = new Dictionary<int, string>();
public void BogusFunct()
{
//comment RemoveWhere call, and everything will work fine
mContainer.RemoveWhere(e => true);
//also bug, try to comment this GetEnumerator call
foreach (var v in dict)
{
}
}
}
public sealed class ThisClassGeneratesTypeLoadException<E>
{
private ThisClassGeneratesTypeLoadException()
{
}
public static ThisClassGeneratesTypeLoadException<T> of<T>(params T[] elements)
{
return null;
}
}
public class TestClass
{
public static readonly TestClass A = new TestClass();
public static readonly TestClass B = new TestClass();
public static readonly ThisClassGeneratesTypeLoadException<TestClass> tst = ThisClassGeneratesTypeLoadException<TestClass>.of(A, B);
}
This issue is part of more huge problem, that stops development of Metro plugin. Could someone recommend workaround?