09-03-2010 12:40 PM - edited 09-03-2010 12:42 PM
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?
Solved! Go to Solution.
09-03-2010 12:47 PM
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?
09-03-2010 01:27 PM
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.
09-03-2010 04:14 PM
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?
09-03-2010 11:29 PM
@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.
09-04-2010 02:32 PM
cschneider, smercurio_fc: 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!
09-07-2010 11:14 AM
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?
09-07-2010 12:07 PM
Bump.
09-07-2010 01:05 PM
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?
09-07-2010 02:48 PM
@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.