TypeLoadException when using classes which inherit from generic types with explicit UnityEngine-namespace struct arguments.
sinai-dev opened this issue · 1 comments
Hey knah, so I found an issue with generic types which I don't think is covered by your known issues.
Consider the following class, assuming it existed in the original game.
public class Test : UnityEvent<Vector2>
This will throw a TypeLoadException if you attempt to access it in any way.
The issue is the explicit generic argument, and the fact that argument type is in the UnityEngine dll. If I used or any System or custom type as the argument it would work fine.
I thought perhaps it was the known blittable struct delegate issue, but this was proven to be unrelated. This does not cause a TypeLoadException:
public struct NonBlittableStruct
{
public string s;
}
public class Test : UnityEvent<NonBlittableStruct>
Nor does this:
public class Test2<T> : UnityEvent<T>
public Test2<Vector2> test;
The same issue affects InputSystem
as well, such as Mouse.current.position
, as the value is a Vector2Control : InputControl<Vector2>
.
Let me know if I can provide any more details!
And again, these are types which exist in the actual game, not new generic types created in a mod. Have not tested if the same issue affects custom mod classes.
Got some more details for you.
I get this different error:
[17:25:13.694] [UnityExplorer] [Error] System.TypeLoadException:
Could not load type of field 'UnityExplorer.ExplorerCore:v2Event' (0) due to:
Expected reference type but got type kind 17 assembly:Assembly-CSharp type:<unknown type> member:(null) signature:<none>
at MelonLoader.MelonHandler.OnApplicationStart () [0x0015d] in <0b18a86417cb47c8b3fed3a346dfca50>:0
So to make sure, I did a quick test. Only the UnityEngine struct types are affected (and only the explicit inheritance ones):
Now that I think about it, it really does sound like this known issue:
Using generics with value types may lead to exceptions or crashes because of missing method bodies. If a specific value-typed generic signature was not used in original game code, it can't be used externally either.
Except this generic signature should exist in the original game, right?