Jump to content

Loading IronPython into KSP


Recommended Posts

This question has been asked before on this forum with no real answer and I can't find any results online. I am try to write a plugin which includes the IronPython.dll to do some python execution. I have included the dll in my plugins folder however ksp is unable to load it throwing several exceptions similar to the following.

AssemblyLoader: Exception loading 'IronPython': System.Reflection.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 AssemblyLoader.LoadAssemblies () [0x00000] in <filename unknown>:0

Additional information about this exception:

System.TypeLoadException: Could not load type 'IronPython.Compiler.Ast.Node' from assembly 'IronPython, Version=2.7.0.40, Culture=neutral, PublicKeyToken=7f709c5b713576e1'.

System.TypeLoadException: Could not load type 'IronPython.Compiler.Ast.DynamicConvertExpression' from assembly 'IronPython, Version=2.7.0.40, Culture=neutral, PublicKeyToken=7f709c5b713576e1'.

System.TypeLoadException: Could not load type 'IronPython.Compiler.Ast.DynamicGetMemberExpression' from assembly 'IronPython, Version=2.7.0.40, Culture=neutral, PublicKeyToken=7f709c5b713576e1'.

I have no idea how to get around this problem. Is there some way of loading non unity plugin dll's into Unity that I don't know of?

Link to comment
Share on other sites

I have no idea how to get around this problem. Is there some way of loading non unity plugin dll's into Unity that I don't know of?

I doubt it can be done.

The version of Mono that is sewn into Unity which your code actually runs on is complete up to .NET 3.5. Dynamic language runtime, without which IronPython won't run, only appeared in .NET 4.0.

My suggestion would be to look into Boo, which is close enough for most practical purposes and which Unity uses internally anyway, so a version is bundled with KSP already.

Link to comment
Share on other sites

Their website states it should work with net3.5 as well and i haven't seen any 3.5 specific feature on a quick first look in the first problematic type. But KSP/Unity does not come with a standard .net runtime, some stuff is missing. This can be a cause of such error messages. I had similar problems once when working with Expressions (IronPython is using them as well) and working around it was... painful. You basically have to figure out what is causing the conflict and provide an alternative implementation. I doubt you want to do this, so same conclusion: Switch to sth else, preferably sth recommended by Unity.

Link to comment
Share on other sites

IronPython has existed for much longer than .NET 4.0, however from v2.6 it had to be compiled specifically for .NET 3.5 to be able to run on it.

If you were to switch to an earlier version the problem you will have is that it requires the namespace System.Diagnostics.Process, which is on Squad's banned list (for good reason), so you'll never be able to load it for that reason.

Link to comment
Share on other sites

I happened to come across http://techartsurvival.blogspot.ca/2013/12/embedding-ironpython-in-unity-tech-art.html which uses 2.6 and may help. Also, the zip package includes 3.5-compatible assemblies in the Platforms/net35 directory.

I don't know how KSP does sandboxing so there might still be issues there if it rejects banned APIs at load time, but if it rejects them at runtime you should still be OK as long as those APIs don't get called.

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...