From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This example demonstrates how to demystify the native .NET library, as it is not shown in any examples.
Description
Here is a brief description of the example:
Assemblies are made of namespaces that contain classes which are to be instantiated and from which members/fields/methods are called.
The first thing to access a .NET object is to load its parent assembly and create an instance of this object.
The assembly must be fully qualified using the "AssemblyName, Version=x.x.x.x, Culture=language, PublicKeyToken=abcdefghij123456" format.
The objects are not known by CVI, but they are comparable to structs, so you need to create as many typedef struct as object types to instantiate. And because you don't know what the struct contain, the definition must be as follows:
typedef struct MyObject* ObjectA;
Because we are dealing with a pointer, CVI does not care at build time what type of data is contained.
The next steps are all about calling a property (Get/Set) and/or a Method. This is done with the CDotNetInvokeGenericMember function. Make sure:
- you are using the right class in the right namespace
- you know all the arguments and their data type
- you know the return type
This sample code show how a homemade assembly named Dummy.dll is called. The assembly source code is attached so you can see how it is written (and how simple it is, hence its name).
The CVI code will load Dummy.dll, instantiate a StrTime object and call the ToString() and GetNow() methods, and finally return both return parameters in a console.
Requirements
Steps to Implement or Execute Code
**This document has been updated to meet the current required format for the NI Code Exchange.**
Eric M. - Senior Software Engineer
Certified LabVIEW Architect - Certified LabVIEW Embedded Systems Developer - Certified LabWindows™/CVI Developer
Neosoft Technologies inc.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
I keep getting this error -6579. I verified all of the paths and have a clean build. any ideas why my .NET is not working?
The assembly I used in this example was generated for .NET 4.5 so you have to make sure you have this version installed on your PC. I'm adding this to the SW Req !
Eric M. - Senior Software Engineer
Certified LabVIEW Architect - Certified LabVIEW Embedded Systems Developer - Certified LabWindows™/CVI Developer
Neosoft Technologies inc.
Ok, So I need to know from the dll's author what .NET is being used?
I checked my Windows 7 PC. The .NET framework is 4.5.2. Any other dependencies?
Sorry about the troubles you are having. I can't replicate this error unless the name of the assembly is wrong. Same goes for 3 different computers here 😕
Are you trying to run the code with the attached assembly? On which function is the error returned (Register or Load) ?
Eric M. - Senior Software Engineer
Certified LabVIEW Architect - Certified LabVIEW Embedded Systems Developer - Certified LabWindows™/CVI Developer
Neosoft Technologies inc.
I have run this on 2 machines, one is a 32bit windows 7 Enterprise sp1, the other one is a 64bit windows 7 Enterprise sp1 Errors on this line status = CDotNetLoadAssembly ("Dummy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", &assmHandle); PrintErr(status); //[=-6579] Variables in main (int) argc = 1 (char**) argv = "Test Calendar.exe." Local Variables in main (char*) TimeString = "360\255\272\... repeated 28 times... p" (char*) ClassName = "360\255\272\... repeated 28 times ... 316\210\1" (int) status = -6579 possible that "Admin privileges" could cause this issue? this is a enterprise managed computer...
Eric my LabWindows CVI is this version: Full Development system (DeBug only) Version 13.0.2 (278)
Eric, Is it possible to turn this into a DLL that can be called from LabVIEW with the call library node so .NET assemblies could then be loaded dynamically in LabVIEW? I've run into the need to do this in LabVIEW several times, and so have others according to the forums.
Also, does the assembly have to be strongly named for this to work? Is there a way to do this without it being strongly named?