Skip to content

kOS entirely broken if certain other mods loaded in KSP 1.7 (GetTypes() reflection problem) #2491

@Dunbaratu

Description

@Dunbaratu

(This is a more complete description of the problem originally coming from issue #2486, which was closed as "wontfix" but on further investigation, this problem is bigger than just Wind Tunnel so I'm opening a more comprehensive issue about it.)

This is a mod interaction bug. So far this problem is known to exist between kOS and two other mods. There may be other mods as well that trigger it.

The two mods are these:

  • Kerbal Wind Tunnel,
  • Kerbal Attachment System.

If either of those two mods are installed and kOS is installed, in a KSP 1.7 game (does not happen in KSP 1.6 or earlier), then kOS is entirely broken and cannot work, with the following symptoms:

  • Cannot attach a kOS computer part to a vessel when building in the VAB. It will not add itself to the vessel when you click.
  • Cannot open the kOS terminal in flight even if a kOS computer part exists.
  • Once the terminal was attempted to be opened, then you cannot leave the scene, and the "escape menu" buttons to go back to the space center or tracking center don't work.

The message appearing in the error log file that indicates the first cause of the problem is this one:

ReflectionTypeLoadException: The classes in the module cannot be loaded.
  at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
  at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0 
  at kOS.Safe.Serialization.SafeSerializationMgr+<>c.<CheckIDumperStatics>b__15_0 (System.Reflection.Assembly a) [0x00000] in <filename unknown>:0 
  at System.Linq.Enumerable+<CreateSelectManyIterator>c__Iterator12`2[System.Reflection.Assembly,System.Type].MoveNext () [0x00000] in <filename unknown>:0 
  at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1D`1[System.Type].MoveNext () [0x00000] in <filename unknown>:0 
  at kOS.Safe.Serialization.SafeSerializationMgr.CheckIDumperStatics () [0x00000] in <filename unknown>:0 
  at kOS.Module.kOSProcessor.OnAwake () [0x00000] in <filename unknown>:0 

(There are other messages in the log after that, but they are the consequence rather than the cause. This error is thrown when trying to activate the kOS PartModule, which then means kOS cannot work after that because our PartModule's OnAwake() didn't finish its initialization work).

Note, if you remove the offending other mods, kOS works fine. As of this writing, those are the only two mods found to cause the problem, and other mods work with kOS just fine.

Note that in both of these other two mods, the other mod throws the same exception trying to call GetTypes() prior to kOS trying to do so.

What I know so far:

  • The problem is that System.Reflection.Assembly.GetTypes() throws an exception if one of these other two mods is installed.
  • Other mods, other than kOS, are also having their GetTypes() calls fail when one of these other two mods is installed, according to what I see in the log it looks as if ALL attempts to call GetTypes() will fail, from any mod, when these two mods exist.
  • Recompiling kOS, using the KSP 1.7 DLLs instead of the KSP 1.6.x DLLs does NOT fix the problem.
  • kOS is targeting .NET 3.5, just like you're supposed to for Kerbal Space Program.
  • Google searching for this problem indicates that GetTypes() throwing this particular exception often happens in Unity programs when there's a DLL in the mix that is for the wrong version of .NET. That could be the problem these other two mods trigger, but I'm not sure.

Trying to come up with a solution

As far as I can tell, I cannot fix the actual problem on our end. I can only provide a weird workaround to deal with the fact that GetTypes() is unusable, and try to find some code change that will make a successful call to GetTypes() entirely optional. (i.e. wrap it in a try/catch, and when it gives this particular error, try to find some alternative thing to do instead.)

Luckily, in the case of kOS, we might be able to make GetTypes() something optional that can be skipped at runtime on user's installs. This is because kOS uses GetTypes() purely to help enforce some of our own internal developer rules that the C# compiler cannot enforce (like "Classes implementing this interface must have this static member, but C# can't do static members in interfaces so instead we enforce this through reflection checks at runtime".) We could make it so that when GetTypes() fails, kOS merely throws up a warning message that developer rules cannot be checked [a warning that us developers care about and users can safely ignore], and it gives up and moves on. At least that way players could still run it.

Metadata

Metadata

Assignees

Labels

bugWeird outcome is probably not what the mod programmer expected.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions