Jump to content

Some mod dependencies can crash the game on load


Heinermann
  • Branch: Live Branch Version: Windows Pending

TL;DR for Devs

The crash occurs in KMod.DLLLoader.LoadDLLs() on a call to Assembly.GetTypes(), it can be resolved by adding a try/catch around the call to GetTypes.

 

Issue Description

Including some dependencies with a mod can lead to failure. For example, adding the massive Jering.Javascript.NodeJS or other large frameworks and including all the dependency DLLs with the mod will trigger the following exception (and trigger the crash dialog).

Exception while loading mod ClusterioBridge at C:/Users/heine/Documents/Klei/OxygenNotIncluded/mods/Dev/ClusterioBridge. 
System.Reflection.ReflectionTypeLoadException: Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown.
  at (wrapper managed-to-native) System.Reflection.Assembly.GetTypes(System.Reflection.Assembly,bool)
  at System.Reflection.Assembly.GetTypes () [0x00000] in <695d1cc93cca45069c528c15c9fdd749>:0 
  at KMod.DLLLoader.LoadDLLs (KMod.Mod ownerMod, System.String harmonyId, System.String path, System.Boolean isDev) [0x0010c] in <b2059d57da244ebc9fb8d55e7bbaa6c7>:0 

  at UnityEngine.Debug.LogError (System.Object message, UnityEngine.Object context) [0x00000] in <72b60a3dd8cd4f12a155b761a1af9144>:0 
  at Debug.LogError (System.Object obj, UnityEngine.Object context) [0x00000] in <3366109ff608488f8317d0b43357f1ba>:0 
  at DebugUtil.LogErrorArgs (UnityEngine.Object context, System.Object[] objs) [0x00000] in <3366109ff608488f8317d0b43357f1ba>:0 
  at DebugUtil.LogException (UnityEngine.Object context, System.String errorMessage, System.Exception e) [0x00000] in <3366109ff608488f8317d0b43357f1ba>:0 
  at KMod.DLLLoader.LoadDLLs (KMod.Mod ownerMod, System.String harmonyId, System.String path, System.Boolean isDev) [0x00000] in <b2059d57da244ebc9fb8d55e7bbaa6c7>:0 
  at KMod.Mod.Load (KMod.Content content) [0x00000] in <b2059d57da244ebc9fb8d55e7bbaa6c7>:0 
  at KMod.Manager.Load (KMod.Content content) [0x00000] in <b2059d57da244ebc9fb8d55e7bbaa6c7>:0 
  at Global.Awake () [0x00000] in <b2059d57da244ebc9fb8d55e7bbaa6c7>:0 
  at UnityEngine.Object.Internal_InstantiateSingleWithParent_Injected (UnityEngine.Object data, UnityEngine.Transform parent, UnityEngine.Vector3& pos, UnityEngine.Quaternion& rot) [0x00000] in <72b60a3dd8cd4f12a155b761a1af9144>:0 
  at UnityEngine.Object.Internal_InstantiateSingleWithParent (UnityEngine.Object data, UnityEngine.Transform parent, UnityEngine.Vector3 pos, UnityEngine.Quaternion rot) [0x00000] in <72b60a3dd8cd4f12a155b761a1af9144>:0 
  at UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, UnityEngine.Transform parent) [0x00000] in <72b60a3dd8cd4f12a155b761a1af9144>:0 
  at UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, UnityEngine.Transform parent) [0x00000] in <72b60a3dd8cd4f12a155b761a1af9144>:0 
  at Util.KInstantiate (UnityEngine.GameObject original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, UnityEngine.GameObject parent, System.String name, System.Boolean initialize_id, System.Int32 gameLayer) [0x00000] in <3366109ff608488f8317d0b43357f1ba>:0 
  at Util.KInstantiate (UnityEngine.GameObject original, UnityEngine.GameObject parent, System.String name) [0x00000] in <3366109ff608488f8317d0b43357f1ba>:0 
  at LaunchInitializer.Update () [0x00000] in <b2059d57da244ebc9fb8d55e7bbaa6c7>:0 
Build: U42-509629-SD

 

I have worked around the issue by creating a separate mod to patch the ONI code before loading the larger mod.

 

 

 


Steps to Reproduce
  1. Develop a mod.
  2. Add some nuget dependencies (i.e. any large framework or package with lots of dependencies).
  3. Reference those packages in your mod and compile it.
  4. Try to load your mod with its new behemoth dependencies.



User Feedback


The same bug happened to me, I already installed, removed all the mods, deleted the cloud and nothing, could you help me solve it and there is almost no information anywhere... :(

Share this comment


Link to comment
Share on other sites

Quote

[14:00:52.115] [1] [INFO] Loading mod content DLL [Clusterio Bridge:ClusterioBridge] (provides DLL)
[14:00:52.118] [1] [INFO] Loading MOD dll: ClusterioBridge.dll
[14:00:52.119] [1] [INFO] Loading MOD dll: ClusterioLib.dll
[14:00:52.120] [1] [INFO] Loading MOD dll: Jering.Javascript.NodeJS.dll
[14:00:52.120] [1] [INFO] Loading MOD dll: Microsoft.AspNetCore.Hosting.Abstractions.dll
[14:00:52.121] [1] [INFO] Loading MOD dll: Microsoft.AspNetCore.Hosting.Server.Abstractions.dll
[14:00:52.122] [1] [INFO] Loading MOD dll: Microsoft.AspNetCore.Http.Abstractions.dll
[14:00:52.122] [1] [INFO] Loading MOD dll: Microsoft.AspNetCore.Http.Features.dll
[14:00:52.123] [1] [INFO] Loading MOD dll: Microsoft.Bcl.AsyncInterfaces.dll
[14:00:52.123] [1] [INFO] Loading MOD dll: Microsoft.Extensions.Configuration.Abstractions.dll
[14:00:52.124] [1] [INFO] Loading MOD dll: Microsoft.Extensions.DependencyInjection.Abstractions.dll
[14:00:52.125] [1] [INFO] Loading MOD dll: Microsoft.Extensions.DependencyInjection.dll
[14:00:52.125] [1] [INFO] Loading MOD dll: Microsoft.Extensions.FileProviders.Abstractions.dll
[14:00:52.126] [1] [INFO] Loading MOD dll: Microsoft.Extensions.Http.dll
[14:00:52.126] [1] [INFO] Loading MOD dll: Microsoft.Extensions.Logging.Abstractions.dll
[14:00:52.127] [1] [INFO] Loading MOD dll: Microsoft.Extensions.Logging.dll
[14:00:52.128] [1] [INFO] Loading MOD dll: Microsoft.Extensions.Options.dll
[14:00:52.128] [1] [INFO] Loading MOD dll: Microsoft.Extensions.Primitives.dll
[14:00:52.129] [1] [INFO] Loading MOD dll: System.Buffers.dll
[14:00:52.130] [1] [INFO] Loading MOD dll: System.Diagnostics.DiagnosticSource.dll
[14:00:52.130] [1] [INFO] Loading MOD dll: System.Memory.dll
[14:00:52.131] [1] [INFO] Loading MOD dll: System.Net.Http.dll
[14:00:52.131] [1] [INFO] Loading MOD dll: System.Numerics.Vectors.dll
[14:00:52.132] [1] [INFO] Loading MOD dll: System.Text.Encodings.Web.dll
[14:00:52.133] [1] [INFO] Loading MOD dll: System.Text.Json.dll
[14:00:52.133] [1] [INFO] Loading MOD dll: System.Threading.Tasks.Extensions.dll
[14:00:52.134] [1] [INFO] Loading MOD dll: System.ValueTuple.dll

the game already has problems with performance.
why screw this monstrous NodeJS to it ?
what do you want to screw up tomorrow ? PostgreSQL server ? or a bitcoin miner ?

in short. ideally, the mod should contain only your dll, and nothing superfluous. if you are developing a mod using libraries created by other modders, for example Plib, then usually they need to be combined using ILRepack.

Share this comment


Link to comment
Share on other sites

On 6/10/2022 at 1:17 AM, Sanchozz said:

the game already has problems with performance.
why screw this monstrous NodeJS to it ?
what do you want to screw up tomorrow ? PostgreSQL server ? or a bitcoin miner ?

in short. ideally, the mod should contain only your dll, and nothing superfluous. if you are developing a mod using libraries created by other modders, for example Plib, then usually they need to be combined using ILRepack.

Who are you to gatekeep what I am doing with modding? I should be able to include any third party libraries to assist with my development. It doesn't need to be Node, it can be anything else. I was only testing something here and won't actually be including Node after all, but my mod WILL have other dependencies from NuGet and there is no possible way to do it otherwise (unless you suggest I stupidly include the source codes of all transitive dependencies).

Also what do you know about the game's performance? You think running a light thread in the background is going to seriously impact it in any meaningful way? I am well aware of the game's performance bottlenecks, I have profiled it myself. It doesn't even matter because any performance hit tradeoff with this scope is worth it.

I really don't need your attitude but I'll consider looking into ILRepack if it's still an issue when I finish everything. However that's not the point. The point is that it is easily fixable with the TL;DR that I wrote above. If ILRepack doesn't work well I'd rather just tell people to preload a second mod which applies the change I mentioned. I think people can manage that much if they want to connect multiple instances of ONI together or send their resources to Factorio, Kerbal Space Program, or other games/servers...

---

EDIT:

Let's for the sake of ending this here, assume that there are two cases:

  1. ILMerging doesn't work on the dependencies and it is infeasible to move them elsewhere such as a subdirectory (or there is a mechanism preventing it).
  2. ILMerging works but it just causes it to crash on the main binary because it contains the same IL as the module that crashed before.
Edited by Heinermann
  • Like 1

Share this comment


Link to comment
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...