03-20-2019 06:44 PM
Hi,
I am trying to figure a way to call an abstract class method from a .dll through .NET. I looked everywhere through forums and it doesn't seem like there is a solution to this. I know that Labview cannot create a constructor for an abstract/interface class so going the normal route of building a constructor will not work. I also tried using a static reference of the abstract class and connecting it to an invoke noke, but I will get a Null object error when I try to run the code. It seems like labview expects me to create a .NET object which I can't do since it is an abstract class. Has anybody run into this problem and found a solution? Many thanks.
03-20-2019 07:39 PM - edited 03-20-2019 07:40 PM
I think you are a bit confused over abstract types and, more importantly, implicit reference type conversions at runtime as a result of a type hierarchy. Reference type conversions are the backbone of polymorphism which means that the compile-time type of a variable is not necessarily the same as the runtime type of a variable.
You can:
At some point someone needs to instantiate a type that derives from that abstract class to use any of these mechanisms. Either LabVIEW can do that with a constructor node for that derived type or some other code can do that within an assembly.
My guess is the former in your scenario - chances are the assembly you are using has some derived types available and there are a bunch of methods expecting any derived type that inherits from the abstract class.
This can be confusing. Maybe post your assembly and what you are trying to achieve and we can give you some more specific (and less theoretical) advice.
03-21-2019 03:52 AM
Without detailed names, or code, the problem remains abstract ...
03-21-2019 11:06 AM
If you can generate a constant for the .NET abstract class, then use a constructor for a real class that implements that abstract class, you can use either the "To more specific class" or "To more generic class" nodes (depending on the hierarchy) to convert the reference into the abstract class, and then see if the method or abstract call works on the converted reference.
03-21-2019 11:09 AM
Sorry to be so vague, the code I have is propietary so I can't post it. I'm not a software person so I'll try to best explain the code in a high level view. I guess what I am trying to do is instantiate a class that uses all the methods from the abstract class on a .dll assembly that was given to me. Labview doesn't let me create a constructor for an abstract class.
So i'm trying to access _classA and all its methods:
_classA is defined as: public abstract class _classA : _classB<configurationClass>, _interface1
_classB is defined as: public abstract class _classB<T> : _classB where T : _classC: configurationClass
configurationClass is the base class for all macine configurations.
Hopefully this explanation doesn't make things more confusing...
03-21-2019 11:18 AM
The presence of angle brackets in .NET indicates the use of Generics, which are sadly part of the list of ".NET Features Unsupported By LabVIEW".
I've found that you can generally use them if generated by some other part of a .NET library, but creating your own instance of one of them is quite difficult, if not impossible.
It's probably easiest to create a DLL of your own in Visual Studio that wraps around the constructor(s) you need and just outputs the returned class. Can you or one of your co-workers do that?
03-21-2019 02:46 PM
I was able to get into the source code and modify it to instantiate a class (copyClass) that inherit the abstract class (_classA) and rebuild the .dll files.
The problem now is in Labview. I created a constructor class of (copyClass) and call out an invoke node for a specific method. Labview return an error "Invoke Node System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
Inner Exception: System.NullReferenceException: Object reference not set to an instance of an object. " It looks like my constructor node is still null for some reason.
Sample copyclass code:
_classA is defined as: public abstract class _classA : _classB<configurationClass>, _interface1
{
"main code here"
}
copyClass : _classA
{
}
03-22-2019 04:14 AM
Some LV code would help... In this situation (simple (and proprietary) code) a screenshot would do...
03-22-2019 03:58 PM
The LabVIEW code and assembly (dll) file if possible - the problem might still not be at the caller end.