Jump to content

Tearing my hair out trying to import Class from another DLL and use it


marzubus

Recommended Posts

Hi,

Summary: TypeLoadException: A type load exception has occurred. when I try to instantiate an object from a Dll compiled for .NET 3.5

I have a simple hello-world style plugin I am trying to load, and then instantiate a instance of a SerialTransport class from CmdMessenger in order to talk to a arduino. Im on MAC. My module and the DLL for CmdMessenger are both built for .NET 3.5. I am copying my main application DLL and the CmdCommand DLL to the plugin dir in KSP's GameData dir. ( Not sure if I need other DLL's or not, but trying to copy ALL of them doenst change anything)

I am using KSPPluginFramework from: https://github.com/TriggerAu/KSPPluginFramework

And CmdMessenger for communicating via Serial to the Arduino.

My module (PsimaxAerospaceControlSystems ) Source and dependencies is up at https://github.com/unixunion/CmdMessenger

The Problem:

The second I try and allocate a new instance of the serial transport class via _serialTransport = new SerialTransport(); the module crashes with


[LOG 21:12:03.553] AddonLoader: Instantiating addon 'PsimaxAerospace' from assembly 'PsimaxAerospaceControlSystems'
[LOG 21:12:03.568] 1/17/2015 9:12:03 PM,PsimaxAerospaceControlSystems,PACS is awake
[EXC 21:12:03.578] TypeLoadException: A type load exception has occurred.
UnityEngine.GameObject:AddComponent()
PsimaxAerospace.PsimaxAerospace:Awake()
UnityEngine.GameObject:AddComponent(Type)
AddonLoader:StartAddon(LoadedAssembly, Type, KSPAddon, Startup)
AddonLoader:StartAddons(Startup)
AddonLoader:OnLevelWasLoaded(Int32)

Its strange because it also doesn't even attempt to print out the Print statement in the line above the instantiation.

Am I trying to do the impossible or how can I load my Serial Comms DLL into my plugin?

/Kegan

Link to comment
Share on other sites

Have a look inside the detailed output/player log. CommandMessenger.dll references System.Diagnostics.Process:

[LOG 13:22:37.605] AssemblyLoader: Loading assembly at \Kerbal Space Program\GameData\CommandMessenger.dll
[ERR 13:22:37.653] Failed to load assembly \Kerbal Space Program\GameData\CommandMessenger.dll:
System.Security.SecurityException: Assembly \Kerbal Space Program\GameData\CommandMessenger.dll tried to use forbidden type System.Diagnostics.Process!
Allows launching of external processes.

You'll either need to find a way to remove that reference or use an alternative method of loading CommandMessenger.dll

Edited by xEvilReeperx
Link to comment
Share on other sites

I have tried to remove those entries but there are some in the upstream dep DLL's which I cannot remove. I have also tried just doing the simple:


using System.IO.Ports;
public static SerialPort _serialPort;
_serialPort = new SerialPort("/dev/tty.usbmodem621", 115200, Parity.None, 8, StopBits.One);

But then I get a new error:


[ERR 22:38:44.978] AssemblyLoader: Exception loading 'PACS': 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 'PACS.PACS' from assembly 'PACS, Version=1.0.5495.40685, Culture=neutral, PublicKeyToken=null'.

Do you know if I can somehow push data to my Arduino via USB or Serial? Im building a force-feedback joystick with readouts on it.

/K

Have a look inside the detailed output/player log. CommandMessenger.dll references System.Diagnostics.Process:

[LOG 13:22:37.605] AssemblyLoader: Loading assembly at \Kerbal Space Program\GameData\CommandMessenger.dll
[ERR 13:22:37.653] Failed to load assembly \Kerbal Space Program\GameData\CommandMessenger.dll:
System.Security.SecurityException: Assembly \Kerbal Space Program\GameData\CommandMessenger.dll tried to use forbidden type System.Diagnostics.Process!
Allows launching of external processes.

You'll either need to remove that reference, do your serial stuff without it or find an alternative method of loading CommandMessenger.dll

Link to comment
Share on other sites

Have a look inside the detailed output/player log. CommandMessenger.dll references System.Diagnostics.Process:

[LOG 13:22:37.605] AssemblyLoader: Loading assembly at \Kerbal Space Program\GameData\CommandMessenger.dll
[ERR 13:22:37.653] Failed to load assembly \Kerbal Space Program\GameData\CommandMessenger.dll:
System.Security.SecurityException: Assembly \Kerbal Space Program\GameData\CommandMessenger.dll tried to use forbidden type System.Diagnostics.Process!
Allows launching of external processes.

You'll either need to find a way to remove that reference or use an alternative method of loading CommandMessenger.dll

Considering System.Diagnostic.Process is blacklisted because it could be used to do severe nasty to someones computer from an AddOn, I hope there is no alternative way to load it!

Link to comment
Share on other sites

Any ideas at all on how I can send data to my arduino? Can I do it over USB instead of Serial?

I don't, as I know nothing about the process, but i'm fairly certain i've seen Arduino mods on here before, so there must be a way. Maybe check out how some of the others are doing it?

Link to comment
Share on other sites

Ive seen some using a http service of sorts which is updated from Unity / KSP and then another daemon updates the actual arduino. I found one guy who managed to get serial and arduino working but on Windows, and I can't use windows since I am going to be having more Joystick axis that windows can handle.

https://github.com/zitron-git/KSPSerialIO

He used what seems like an arcade serial library and I've seen attempts in the forums over the span of a year to get it working on *nix but no luck.

I was wondering if there is some other more unity approved method of talking with hardware, even perhaps full on PID / HID integration on joystick level? though I have no idea how to write the structs for the HID/PID reports to achieve this.

/K

- - - Updated - - -

I also found this, but I do not know if it can be loaded up into just any Unity game?

https://www.assetstore.unity3d.com/en/#!/content/6804

If it can be that would rock!

Link to comment
Share on other sites

I have managed to put together my own serial library for Mac, Linux and possible Windows too. Its up at: https://github.com/unixunion/PsimaxSerial if anyone is interested in pure serial comms from KSP to Arduino ( or other serial devices ).

I also modded KSPSerialIO to use my library and it works at least for me: https://github.com/unixunion/KSPSerialIO

/K

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