Jump to content

Mods with wrong .NET Target Framework


Recommended Posts

Since 1.6 I've been seeing more frequent random crashes with really no clue where they come from, so I've been spending time since 1.7 chasing exceptions in the KSP.log. Today I found a fix for a TypeLoadException I was getting during startup. I know KSP plugins should target .NET 3.5, but how critical is this? Could this be a source of random crashes or is it just sloppy programming by the modders? 

Spoiler

[EXC 22:11:47.643] TypeLoadException: Could not load type 'System.Runtime.Versioning.TargetFrameworkAttribute' from assembly 'DecouplerShroud'.
	System.MonoCustomAttrs.GetCustomAttributesBase (ICustomAttributeProvider obj, System.Type attributeType)
	System.MonoCustomAttrs.GetCustomAttributes (ICustomAttributeProvider obj, System.Type attributeType, Boolean inherit)
	System.Reflection.Assembly.GetCustomAttributes (System.Type attributeType, Boolean inherit)
	Kopernicus.LogAggregatorWorker.Awake ()
	UnityEngine.GameObject:AddComponent(Type)
	AddonLoader:StartAddon(LoadedAssembly, Type, KSPAddon, Startup)
	AddonLoader:StartAddons(Startup)
	<LoadObjects>c__Iterator1:MoveNext()
	UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
	<CreateDatabase>c__Iterator0:MoveNext()
	UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
	GameDatabase:StartLoad()
	<LoadSystems>c__Iterator0:MoveNext()
	UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

 

What I tracked down is:

  • Decoupler Shroud was compiled against .NET 4.6.1 @navot
  • Dynamic Battery Storage (Near Future Electrical dependency) was compiled against .NET 4.0  @Nertea
  • Docking Port Sound FX was compiled against 4.5.2 @tg626

Recompiling locally against .NET 3.5 clears the exception. I found these by downloading the problem mods and checking the project properties in Visual Studio. I double checked the rest of my mods with  dotPeek and didn't find any other issues.

If a mod reads this: I'm not sure where this topic should go.

Edited by Tonka Crash
pinged affected mod writers.
Link to comment
Share on other sites

1 minute ago, HebaruSan said:

Good eye. Yes, I believe this could cause problems. I've taken the liberty of reporting this on those mods' respective bug trackers, hopefully it'll be resolved.

You beat me to it on two of the three :)

Link to comment
Share on other sites

17 hours ago, Tonka Crash said:

 I know KSP plugins should target .NET 3.5, but how critical is this? Could this be a source of random crashes or is it just sloppy programming by the modders? 

Not too much critical, as anything wrong would cause the exception you detected. DLL have this name for a good reason: they are Dynamic Linking Libraries, i.e., the code is linked in runtime, not on compile time (or even loading time).

Jumping over versions can be a problem when the interface is preserved (ie, the function has the same parameters and return type), but not the contract (the function does something different than expected). But this is not a problem while compiling, but while running - and Microsoft is not (too much) dumb, they preserve the function's contracts between major versions.

On this specific case, it's the compiler the source of the trouble - since it was told to target the 4.x version, the compiler generated code that relies on new classes and methods that are not available on the 3.x version.

About the sloppiness… It's more a unattended mistake on what is called "configuration management" than a bad practice on programming. Microsoft Visual Studio automates everything it can to make the programmer's life easier, but now and then the defaults changes to newer versions of the libraries, and the programmer is not notified and the guy just realizes the problem on deploy.

Edited by Lisias
krakens count the tyops!!!
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...