BepInEx / Il2CppInterop

A tool interoperate between CoreCLR and Il2Cpp at runtime
GNU Lesser General Public License v3.0
206 stars 66 forks source link

Creating a new Il2CppStructArray has a chance to cause a InvalidOperationException #82

Closed r-Lxd closed 1 year ago

r-Lxd commented 1 year ago

Depending on what game you're trying to mod (I was doing this on Sons of the Forest), this Line will throw a InvalidOperationException (Sequence contains more than one matching element) error

This causes old libraries such as UniverseLib to break.

I fixed this by manually changing Select to FirstOrDefault in DnSpy

Kasuromi commented 1 year ago

This isn't an issue with Il2CppInterop, we assume that there will be one instance of Il2Cppmscorlib.dll present in the AppDomain. Swapping Single for First only moves the issue to another place and you might run into a problem where something references the 1st loaded Il2Cppmscorlib but another references the 2nd one.

In the case of UniverseLib, it's a known issue with UniverseLib that it loads multiple new AssemblyLoadContexts.

If your plugin is using Assembly.LoadFile, you should switch to Assembly.LoadFrom to ensure you are loading the assembly in the default context which would prevent multiple instances being present.