LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Build .NET Interop Assembly

Solved!
Go to solution
Good morning Guys, Yesterday, I've realized a simple VI that, passing a 1D array, returns a simple multiplication of each array elements. I've also tried to build a .Net Interop Assembly....and it works fine on Visual Basic. Today, I've just made a VI that makes a simple signal processing (butterworth) on a simple 1D array (DBL). I've tried to build a .Net Interop Assembly and I have a lot of problems.... First of all I can't use my .dll on labview (strange???): This is the error: Error 1172 occurred at Error calling static method nsbutter.clbutter.filtro, (System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. Inner Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.) Moreover, library doesn't work on VB because it tries to start il VI itself. Can you help me? Attachment is a zip that contains: - filtro.vi: the source file - butterworth.dll: built version of my source - usodll.vi: a VI that use my dll Thank you so much
0 Kudos
Message 1 of 19
(5,090 Views)

no attachment...

0 Kudos
Message 2 of 19
(5,082 Views)

I'm sorry 😄

0 Kudos
Message 3 of 19
(5,079 Views)

I don't understand. I thought you said that you have a .NET interop assembly. Where is the LabVIEW project that created this assembly? Was this assembly created in LabVIEW, or Visual Studio?

 

If you are calling a static method you do not create an object using a constructor. By definition, a static method is not tied to an object, but to a class. Hence, you would have just the Invoke node.

 

I don't see your code actually doing anything (usodll VI). There's no arrays, no nothing.

0 Kudos
Message 4 of 19
(5,063 Views)

First of all, thank you!

I've modified usodll.vi with a simple, complete, example...that it does not work 🙂

Inside "Builds" you will find .Net Interop built in Labview and, in main directory, you can find the project.

 

I have no skills about .NET this is my serious limit! 🙂

 

Thank you for your consideration.

 

 

0 Kudos
Message 5 of 19
(5,053 Views)

Define "does not work".

 

As I noted, when you are calling a static method, do not use a constructor. Delete the constructor and the wire between the constructor and the invoke node.

0 Kudos
Message 6 of 19
(5,036 Views)

I don't understand why, but this morning it works fine (???)

If i delete the constructor how can I use it?

Can you make me a simple example?

 

Thank you

0 Kudos
Message 7 of 19
(5,034 Views)

@teoprimo wrote:

 

If i delete the constructor how can I use it?


You use it exactly as is. Simply delete the constructor. The VI will still work. As I said, for static methods, a constructor is not needed. Please refer to the LabVIEW Help. It has a page on using static methods and properties. Fundamentals -> Windows Connectivity -> How-To -> .NET -> Using Static .NET Properties and Methods.

0 Kudos
Message 8 of 19
(5,032 Views)

Ok, it works.

Now, I've to use this .dll in VB.

To simplify the operations, I've built another simple .dll, attached to this post.

 

Imports System.Windows
Imports nsfiltroBW

Public Class Form1


    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        Dim Input(1000) As Double
        Dim j As Integer
        Dim Output(1000) As Double

        For j = 0 To 1000
            Input(j) = j
        Next

        Dim prova As New nsfiltroBW.cnfiltroBW()
        prova.filtroxVB(Input, Output)

        Dim presi(1000) As Double
        presi = Output

    End Sub


End Class

 

I've added my library on Project via Project -> Add reference

There is no error but, when VB calls the library, it opens a white labview interface and it stops to work (no feedback just this interface).

 

Can you help me?

 

Thank you so much

 

0 Kudos
Message 9 of 19
(5,023 Views)

Are you sure you uploaded the right project? The project has no build specifications. Also, that code doesn't make much sense to me. If you're creating static methods from the interop assembly, again, you should not be calling constructor code.

0 Kudos
Message 10 of 19
(5,017 Views)