LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Failed to create Constructor node from .NET Core Library

Hello, I have troubles creating Constructor Node from .NET core library. 
When I select object (green) in library I do not see any available constructors (red). I am able to click "OK" button, but Constructor node stays empty. Do you know what causes this? 

soundslikesound_2-1728903465918.png

Usually when object do not have public constructor, it looks like this, and OK button is disabled. See picture below.

soundslikesound_3-1728905024091.png

 

 

0 Kudos
Message 1 of 10
(476 Views)

Not all item in the .Net lib can create Constructor.

For static items, you can use properties nodes/invoke node directly without a constructor.

 

George Zou
0 Kudos
Message 2 of 10
(446 Views)

Just quickly checked this and it works

 

Source:

 

 

namespace netCore;

	public class MathClass    
    {    
        public MathClass() { }    
    
        public double Calculate(double num1, double num2, string op)    
        {    
            double result = 0;    
            switch (op)    
            {    
                case "Add":    
                    result = num1 + num2;    
                    break;    
                case "Sub":    
                    result = num1 - num2;    
                    break;    
                case "Mul":    
                    result = num1 * num2;      
                    break;    
                case "Div":    
                    result = (double)num1 / num2;                      
                    break;    
                default:           
                    break;    
            }    
            return result;    
        }    
    }

 

Call:

Screenshot 2024-10-14 18.28.04.png

 

Unfortunately I haven't 32-bit LabVIEW in my hands, may be 64/32 bitness is your problem?

 

Try to build your library as

 

 

dotnet build --runtime win-x86

 

 

0 Kudos
Message 3 of 10
(424 Views)

Hello zou, I am aware that, I am already using some static methods from .NET Framework library. However I am confused, how do I choose  property/invoke node for .NET Core or .NET Framework. When select DLL (which is readable for .NET Core Constructor Node) for Property Node I get error below. 

soundslikesound_1-1728989160523.png

 

For Constructor node there is an option to choose from .NET Framework/.NET Core, I don't see that for Invoke/Property node.

soundslikesound_1-1728989738684.png

Can you help?

 

 

0 Kudos
Message 4 of 10
(389 Views)

@soundslikesound  a écrit :

For Constructor node there is an option to choose from .NET Framework/.NET Core, I don't see that for Invoke/Property node.


You don't need this, because the option .NET Framework/.NET Core is only for the constructor, and from this point there are no any differences in term of called methods.

 

Another reason is why you have such trouble is dependencies. If your .net "SQL" assembly dependent on other DLL, and this dependent DLL (could be related to SQL in your case) cannot be located properly when called from LabVIEW, then you will get an error. Try to prepare a very simple .net core (or take it from examples <LabVIEW>\examples\Connectivity\Dot NET Core") and check if it works and how, then add additional complexity to your code.

0 Kudos
Message 5 of 10
(377 Views)

Hi Andrey, thank you for your answers. I rebuild my company DLLs to 32bit, otherwise I got error 'Error occured trying loading assembly', so that should be an issue.

 

I also created simple .NET Core library with method returning true/false, Constructor node works just fine. 

 

I will probably have to create new test project for my DLL and slowly add additional complexity to my code, like you already wrote.

 

namespace LibraryTest
{
    public static class Class1
    {
        public static bool Method1()
        {
            return true;
        }
    }
}

Still I have troubles to work with invoke/property nodes. I have written this simple library (source above) with static method. I am able to load it with Constructor node, I am able to see Class1 and upon selecting it gives me error 'This class contains no public constructors', which is OK. Works as it should be.

soundslikesound_0-1728994798433.png

 

However when I try to create Property Node and load DLL I got error 'Error trying to load assembly'. 

soundslikesound_1-1728994889220.png

Same library can be loaded through .NET Core Constructor, can not be loaded through Propery Node. Am I missing something? 

 

0 Kudos
Message 6 of 10
(371 Views)

@soundslikesound  a écrit :

Am I missing something? 

 


Yes, just slightly modify your code like this:

 

namespace LibraryTest
{
	public class Class1
	{
		public Class1() { }
		public bool Method1()
		{
			return true;
		}
	}
}

and you will get it:

 

Screenshot 2024-10-15 15.50.54.png

 

In my understanding you must have a constructor for the LabVIEW node and in general the best practice is to avoid public static... You creating instance in LabVIEW and static is actually not a member of instance, but member of type. Or did you trying to implement kind of singleton pattern?

0 Kudos
Message 7 of 10
(362 Views)

Also, .Net Core support in LabVIEW is preliminary and not complete. It has been stated that way by NI developers. They did debate if they should release what they have or wait another release cycle until they have more working. Eventually they decided to release what is present and use the feedback to prioritize the work to be done next. It will take more than one additional release before .Net Core is fully working as intended (and no that won't mean it will support every possible feature from .Net).

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 10
(354 Views)

Hello Andreay, sorry for late reply. 

 

I feel I am solving two different issues simultaneously.

 

1. I am forced to use static properties from our company solution/library and currently I am trying to switch from .Net Framework Library to .Net Core Library. They both share even the same source code. So far I am unable to use static properties from .Net Core Library. And yes, it is probably singleton pattern (terminology is not exactly my cup of tea :-D). There is probably bug in labview which stops me. 

 

2. I am unable to see any public constructors in my 'SQL' company library. I thought there is problem in overloading or there are problematic variable types in class constructors (as NI meantioned here) however this test code works fine: 

 

namespace LibraryTest
{
    public class Class1
    {
        public Class1()
        {

        }

        public Class1(List<int> a)
        {

        }

        public bool Method1()
        {
            return true;
        }
        public bool Method1(string b)
        {
            return true;
        }
        public bool Method1(List<string> b)
        {
            return true;
        }
    }
}

 
I will try to build 'SQL library' from scratch and see when it starts to fail. 

0 Kudos
Message 9 of 10
(251 Views)

Hello rolfk, sorry for late reply.

 

I am totally aware of issues you wrote. However since .Net Core support is Preview feature it is difficult for me to find out if there is bug to fix in Labview or I am doing something wrong. I really expected .Net Core support for years from NI so started testing it as soon as it was possible. Lets hope .Net Core support will be soon fully working. 

0 Kudos
Message 10 of 10
(250 Views)