[SOLVED] Cannot load DLL to Unity

Hi,
I connect my Unity project with microprocessor which will be my “gamepad” for simple 2D game. I need to use serial port for connection with device so I added dll to Unity, which should make it works.

Sounds simply, but when I tried to use my library, Unity shows error:
Error log

Unhandled Exception: System.TypeLoadException: Could not load type ‘STMInputDLL.STMInput’ from assembly ‘STMInputDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’.

at (wrapper managed-to-native) System.MonoType:GetMethodsByName (string,System.Reflection.BindingFlags,bool,System.Type)

at System.MonoType.GetMethods (BindingFlags bindingAttr) [0x00000] in :0

at Mono.CSharp.MemberCache.AddMethods (BindingFlags bf, System.Type type) [0x00000] in :0

at Mono.CSharp.MemberCache.AddMethods (System.Type type) [0x00000] in :0

at Mono.CSharp.MemberCache…ctor (IMemberContainer container) [0x00000] in :0

at Mono.CSharp.TypeHandle…ctor (System.Type type) [0x00000] in :0

at Mono.CSharp.TypeHandle.GetTypeHandle (System.Type t) [0x00000] in :0

at Mono.CSharp.TypeHandle.GetMemberCache (System.Type t) [0x00000] in :0

at Mono.CSharp.TypeManager.MemberLookup_FindMembers (System.Type t, MemberTypes mt, BindingFlags bf, System.String name, System.Boolean& used_cache) [0x00000] in :0

at Mono.CSharp.TypeManager.RealMemberLookup (System.Type invocation_type, System.Type qualifier_type, System.Type queried_type, MemberTypes mt, BindingFlags original_bf, System.String name, IList almost_match) [0x00000] in :0

at Mono.CSharp.TypeManager.MemberLookup (System.Type invocation_type, System.Type qualifier_type, System.Type queried_type, MemberTypes mt, BindingFlags original_bf, System.String name, IList almost_match) [0x00000] in :0

at Mono.CSharp.Expression.MemberLookup (Mono.CSharp.CompilerContext ctx, System.Type container_type, System.Type qualifier_type, System.Type queried_type, System.String name, MemberTypes mt, BindingFlags bf, Location loc) [0x00000] in :0

at Mono.CSharp.Expression.MemberLookupFinal (Mono.CSharp.ResolveContext ec, System.Type qualifier_type, System.Type queried_type, System.String name, MemberTypes mt, BindingFlags bf, Location loc) [0x00000] in :0

at Mono.CSharp.New.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0

at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in :0

at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0

at Mono.CSharp.Assign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0

at Mono.CSharp.SimpleAssign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0

at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in :0

at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0

at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.BlockContext ec) [0x00000] in :0

at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0

at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0

at Mono.CSharp.ToplevelBlock.Resolve (Mono.CSharp.FlowBranching parent, Mono.CSharp.BlockContext rc, Mono.CSharp.ParametersCompiled ip, IMethodData md) [0x00000] in :0

Internal compiler error at Assets/_Scripts/Player/PlayerBehaviourVCP.cs(20,14):: exception caught while emitting MethodBuilder [PlayerBehaviourVCP::Start]
The class System.IO.Ports.SerialPort could not be loaded, used in System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

I set project target for “Unity3d .net full Base Class Libraries”

Part of code in Unity with my class:

using UnityEngine;
using STMInputDLL;
using System.Threading;

public class PlayerBehaviourVCP : MonoBehaviour {
    private STMInput STM_Input;
    private Thread VCP_Thread;
   
    void Start() {
        STM_Input = new STMInput();
        if (STM_Input) {
            Debug.Log("VCP WORKING!!!");
        } else Debug.Log("VCP doesn't work :<");
        //other inits for player...
    }
    //other methods
}

Okay, problem solved accidentally :smile:
I found solution there:

Problem was with classes connected to IO ports. Unity not load it as default.