Property (Variant) of interface is not initialized in Unity. Same command works in Visual Studio.

Hello everyone, this is the situation:

I have a type library (.tlb) that allows me to communicate with a program run in windows (Aspen Hysys 10, but I suspect this is not relevant).

  • In this library there is a certain property (RealFlexVariable.Values) defined as Variant.
  • The library has been converted to a .dll with tlbimp.

When I run the exact same code in Unity 2018.3.11f1 and in Visual Studio 2017, referencing the same dll and communicating with the same instance of Aspen Hysys, this happens:

  • The property is returned as a dynamic in VS, everything works properly.
  • The property is returned as a System.Object in Unity, and is not initialized when I call it. It will return an error whenever I use it later, indicating that it is not set to a reference of an object.

It is important to note that all other methods and properties (booleans, doubles, interfaces, etc) are obtained correctly in both VS and Unity, it is only in the ones defined as Variant that this difference appears.

I think some people will feel the need to ask to post the code. But the whole point of the error is that the same commands work on Visual Studio. The code is not the problem, the problem must be in differences in the communication protocol of Unity and Visual Studio. Whether there is a solution or not I do not know, but I hope someone does.

Thank you for your help.

This might be a bug in Mono, which Unity uses when running in the editor.

I recommend posting this here, as that’s the forum that the people who work on C#/.NET nitty-gritties read. You should also create a bug report.

1 Like

Thank you Baste, I will post it there as well. Sadly I have no previous experience with mono but I will look there too.

Edit: Also, should I delete this post or leave it up in both forums?

You can’t delete posts on these forums, so no choice there :stuck_out_tongue:

There’s a lot of scrubs that would otherwise insta-delete their threads once they have an answer, which would mean that other people wouldn’t find those posts when searching, so deletion is dissallowed for that.

:face_with_spiral_eyes: Then for hypothetical future readers I will leave the link to the same post in the other subforum: Property (Variant) of interface is not initialized in Unity. Same command works in Visual Studio.

Despite this, providing a repro is important. There are many, many differences between code compiled by VS for pain old windows CLR vs for Unity. Many of the differences are benign 99% of the time, but perhaps you have found a corner case, known or not. In order to identify which difference is causing the problem, even if it is well known, a troubleshooter will need to understand your problem intimately. A repro in code is always the ultimate tool for that, so I don’t think you should be surprised if someone asks to see the code.