LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble with .NET DLL calling a "secondary" DLL

Solved!
Go to solution

I have LabView using a .NET dll, and I've been troubleshooting why it isn't working properly for quite some time. This .NET dll (call it "primary") calls other ("secondary") .NET dll's.

 

While testing the primary dll in LabView, I created a function that simply returns "true" and in LabView an LED will turn on if "true" is returned. This works correctly and the LED turns on.

 

What doesn't work, is if I create a function in the secondary assembly that returns "true", and then call this function in the primary's function.

 

For example, this WORKS:

 

PRIMARY:

 

 

public bool TrueFalse()
{
	return true;
}

 

 

This DOESN'T WORK:

 

PRIMARY:

 

 

public bool TrueFalsePrim()
{
	return temp.TrueFalseSecond();
}

 

SECONDARY:

 

 

public bool TrueFalseSecond()
{
	return true;
}

 

'temp' is a variable declared in "primary" of type "secondary", and 'TrueFalseSecond' is a method declared in "secondary".

 

I believe I've narrowed it down to the primary dll using a secondary dll, as it works if I just "copy" all the C# code into the primary file before building the project.

 

Any ideas?

0 Kudos
Message 1 of 11
(3,446 Views)

There must be more to your code than you're showing. I'm assuming "temp" is created in the constructor for "primary"? The biggest problem you have with secondary calls to provate assemblies is to make sure the assemblies reside in the search path. Do both assemblies reside in the same directory? Are they in the same folder as the VI? Can you upload your VI and your .NET code?

Message 2 of 11
(3,439 Views)

Yes there's definitely more code than I'm showing. I'm just showing how it works. Yes temp is declared in primary. Both assemblies are in the same directory. I've tried having them in the same folder as the VI and elsewhere and neither works.

 

Unfortunately I can't upload the .NET code.

 

It breaks as soon as I try to call a function from the secondary. If I bring the function into the primary it works, but I can't do that in the long-term.

0 Kudos
Message 3 of 11
(3,434 Views)

you are sure everything is right with your constructor? as temp seems to be an object with a member-function you call, there should be any indication in your secondary that the function you call belongs to that class...also you are sure your exports of secondary are declared right so you can call the function from your primary dll?


THINK G!! 😉
------------------------------------------------------------------------------------------------
Using LabView 2010 and 2011 on Mac and Win
Programming in Microsoft Visual C++ (Win), XCode (Mac)
Message 4 of 11
(3,426 Views)

 


@thomashw wrote:

Yes there's definitely more code than I'm showing. I'm just showing how it works. Yes temp is declared in primary. Both assemblies are in the same directory. I've tried having them in the same folder as the VI and elsewhere and neither works.

 

Unfortunately I can't upload the .NET code.

 

It breaks as soon as I try to call a function from the secondary. If I bring the function into the primary it works, but I can't do that in the long-term.


Why can't you upload the .NET code? What you're showing does not seem to be very proprietary. Have you tried paring down the 2 assemblies to just the functionality you're showing? Perhaps something else is going on and it only appears when you have all fo the code.

 

Message 5 of 11
(3,419 Views)

cschneider: I can't upload the code because it belongs to my company and I'm sure they wouldn't be happy if I did. On Monday I'll try removing everything from the two classes except what I have here and I'll report back. If it doesn't work, I'll upload everything for you to have a look.

 

Thanks for the help so far!

0 Kudos
Message 6 of 11
(3,403 Views)

Okay, here's my code and my .vi.

 

As you can see, class1 is a child class of class2, and class2 has a variable of type class3.

 

With my .vi, if "true" is returned, the light should turn from red to green. This doesn't happen. Placing 'return true;' in the class1 Connected() method does turn the light on, so I don't believe there's anything wrong with the .vi.

 

 

// Class1.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace test
{
    public class Class1 : Class2
    {
        public bool Connected()
        {
            return temp.ConnectClass3();
        }
    }
}

 

// Class2.cs

using System;
using System.Collections.Generic;
using System.Text;
using class3;

namespace test
{
    public class Class2
    {
        public Class3 temp;
    }
}

 

// Class3.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace class3
{
    public class Class3
    {
        public bool ConnectClass3()
        {
            return true;
        }
    }
}

 

Any ideas as to why it's not working?

 

 

0 Kudos
Message 7 of 11
(3,364 Views)

Bump.

0 Kudos
Message 8 of 11
(3,357 Views)

Have you been able to use this DLL in another programming environment? Also, is there any way you could implement some error checking to see if the second DLL executes at all?

Tanya Visser
National Instruments
LabVIEW Group Manager
Message 9 of 11
(3,346 Views)
Solution
Accepted by topic author thomashw

 


@thomashw wrote:

Bump.


 

Please learn some patience. This forum is made up primarily of volunteers, many of whom (like myself) have full-time jobs and we cannot answer questions at the drop of a dime.

 

Now, as to your issue. Your problem is not with LabVIEW, but with basic C#. The following line in Class 2:

 

public Class3 temp;

does nothing. It's a declaration only. There is no creation of "temp". Thus, when you try to access temp.ConnectClass3() you would have gotten a .NET run-time error because the object doesn't exist. If you had wired the error handling I/O and placed an error cluster indicator you would have seen the error condition. If you change your line to "public Class3 temp = new Class3();" then the code will work.

Message 10 of 11
(3,336 Views)