Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

DLL Event Subscription Issue

Discussion in 'Scripting' started by Acidictive, Aug 14, 2019.

  1. Acidictive


    Aug 27, 2015
    Hi everyone!

    This is my first time posting on the forums because I'm quite desperate. I just hope some of you good people might had the bad luck to witness the same error as me.

    I'm trying to use an external DLL file called Vector.CANoe.Interop.dll which provides interface with the software called CANoe (from the company Vector), but every time I try to subscribe a function call to an event, unity throws NotSupportedException upon launching.

    The exception logged in Unity:
    NotSupportedException: non imported interfaces on imported classes is not yet implemented. (wrapper cominterop) CANoe._IEnvironmentVariableEvents_Event.add_OnChange(CANoe._IEnvironmentVariableEvents_OnChangeEventHandler) (wrapper cominterop-invoke) CANoe._IEnvironmentVariableEvents_Event.add_OnChange(CANoe._IEnvironmentVariableEvents_OnChangeEventHandler) DummyClass.Start () (at Assets/DummyClass.cs:20)

    Important things so far:
    • I'm using the latest version of Unity (2019.2) but I've also tried with 2018.3.
    • I'm using Visual Studio Professional (2017).
    • We've already used this DLL file with WPF/WinForms based projects succesfully.
    • We can use the interfaces that the DLL file provides, but we cannot subscribe event.
    • My DLL file is indeed inside the /Assets/Plugins folder (also it is visible under References in the CSharp project.
    • I have valid license for the software providing the DLL, for Unity and for Visual Studio as well

    My Code:
    Code (CSharp):
    1. public class DummyClass : MonoBehaviour
    2. {
    3.     private CANoe.Environment canoeEnvironment;
    4.     private EnvironmentVariable dummyEnvVar;
    5.     private int i = 0;
    7.     void Start()
    8.     {
    9.         canoeEnvironment = (CANoe.Environment)new CANoe.Application().Environment;
    10.         dummyEnvVar = (EnvironmentVariable)canoeEnvironment.GetVariable("EnvSim_DummyEnvVar");
    11.         dummyEnvVar.OnChange += DummyFunction;     // problematic line  
    12.     }
    14.     public void DummyFunction(object value)
    15.     {
    16.         i++;
    17.     }
    19. }
    Any help would be appreciated!

  2. palex-nx


    Jul 23, 2018
    NotSupportedException is special exception type to indicate what some features are not supported on current platform/setup. Usually it is thrown intentionally by software developers. I suppose there's something in mono + com interop wich is not supported. If your target platform is windows only, I sugges you build simple console .NET app and utilize that lib through that app's stdio. Anyway your best bet would be to ask Vector company devs if ther product is compatible with unity/mono environment.
    Acidictive likes this.