LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to create delegate using system.eventhandler'1 with CVI.NET

Solved!
Go to solution

Hi everyone,

 

I am using Labwindows/CVI 2012 and I am try to register a delegate with a parameter using the system.eventhandler'1 (in mscorlib.dll). I get always the same run-time error -6578  "could not load the required type information".

 

I've noticed that the error happen just, when the generics, that I am passing, belongs to a different assembly. For example, if a take the generic "System.UnhandledExceptionEventArgs", it works fine, but using "System.Xml.Serialization.XmlNodeEventArgs" it would not work.

I am using the wrapper automatically generated from Labwindows and the .NET framework is 4.0 (mscorlib assembly version 4.0.0.0).

The command look like this:

 

System_EventHandler_T1__Create(&SystemEventHandler1,"System.Xml.Serialization.XmlNodeEventArgs",  XmlSerNodeEvent, NULL, &ExceptionHandle); 

 

I am pretty sure that both assemblies were correctly loaded and they are both in the GAC (I am able to use the other functions in the assemblies).

 

Should I do something special to make the second assembly "visible" to mscorlib assembly?

 

I thank in advance for the answers.

 

Best regards,

Andrea

0 Kudos
Message 1 of 9
(5,982 Views)

Hi Andrea,

 

I can imagine two causes of this error message.

 

One is, that CVI can not load the information because it misses some information to link to the assembly. Since you are using a GAC assembly there should be normally all information available, but you can take a look into this, if you want with the following link:

 

Calling a Visual Basic DLL From LabWindows™/CVI - National Instruments
http://digital.ni.com/public.nsf/allkb/AA35D259FD350D3E8625699F0059C641?OpenDocument

 

The second cause may be a return value, that can not be handled by CVI itself. I think the handle is the one, that can cause the issue here.

when passing data between C and .NET not all data types and objects can be casted automatically. Under the following link you can find a list:

 

Converting .NET Data Types to C Data Types - LabWindows™/CVI™ 2013 Help - National Instruments
http://zone.ni.com/reference/en-XX/help/370051Y-01/cvi/libref/cvidotnet_convertingdatatypes/

 

The handles are mentioned here, too.

 

Best regards,

Melanie

Best regards,
Melanie Eisfeld
Senior Applications Engineer, National Instruments Germany
Certified LabVIEW Developer
Certified TestStand Architect
0 Kudos
Message 2 of 9
(5,951 Views)

Hello Andrea,

 

How did you resolve this issue?  I'm having a silmilar problem using eventhandler'1.

 

Best regards,

Darrel

0 Kudos
Message 3 of 9
(5,017 Views)
Solution
Accepted by topic author acambruzzi

I wanted to respond to this page since there's no resolution. Two notes about System_EventHandler_T1__Create:

 

  1. Check the function help for TEventArgs - you most likely need to pass the fully qualified assembly name.
  2. If your assembly isn't in the GAC or the application directory, you'll need a config file so that mscorlib will know where to find it (it also needs to be strong-named if it's not in a subdirectory of the application directory). 

I'd highly recommend reading through this page if you have questions about this:

MSDN: How the Runtime Locates Assemblies

 

Hope this helps!

Trent

 

https://www.linkedin.com/in/trentweaver
0 Kudos
Message 4 of 9
(4,494 Views)

Hi,

 

I want to check with you if your issue was resolved, I am currently having little trouble with the System_EventHandler_T1_Create(), and I am suggested the same solution, would you be open in sharing your piece of snippet which contains this function, I am unaware about the function specific name for TEventArgs. I am attaching my piece of code with using function. Your help is appreciated. Thanks! 

0 Kudos
Message 5 of 9
(3,501 Views)
Solution
Accepted by topic author acambruzzi

Unfortunately, I don't have the test case i used handy.

 

Like i mentioned above, you should check the control help in the function panel. You can see the help topic for a specific parameter by right clicking on the parameter in the function panel. TEventArgs should include something like this:


"If the type you pass is defined in mscorlib or in the target assembly, then you can just pass the full name of the type. If not, you must pass the assembly-qualified name of the type, that is, the full name of the type followed by the assembly information, separated by a comma."

You should try this and add error handling to catch exceptions - in your case, it should look something like:

int                    status;
CDotNetHandle          excptHdl;
status = System_EventHandler_T1__Create (&CommStateChangedHandler, "MyCimetrix.ComStateChangedEventArgs, MyCimetrix", CommStateChanged, NULL, &excptHdl);

That's assuming the name of your assembly is "MyCimetrix.dll" and is located in the same directory as the executable. If the function returns an error, try using the CDotNet library to get the exception info.

 

Trent

 


 

https://www.linkedin.com/in/trentweaver
0 Kudos
Message 6 of 9
(3,491 Views)

Hi Trent,

 

Thanks for your response. I decided to put your code of lines in my callback of Set Value, put a break point to see if there is any value to CommStateChangedHandler, initially I got uninitialized and then I declared it as a zero, I got NULL value later, do you think you could suggest in terms of how to initialize? Attaching a pic here, Again thanks for any help and suggestion.

 

-Riddhi

0 Kudos
Message 7 of 9
(3,481 Views)

I finally figure out what was the problem calling the event handler: in order to be recognized the TEventArgs must be provided with the fully string describing the assembly as in the following example.

 

System_EventHandler_T1__Create(&myRobot.ChangedConnectionStateHandle, "ABB.Robotics.Controllers.ConnectionChangedEventArgs,ABB.Robotics.Controllers.PC, Version=6.2.6753.1029, Culture=neutral, PublicKeyToken=null", ConnectionChanged, NULL, &ExceptionHandle) ;

 

Thank you everyone for the support.

0 Kudos
Message 8 of 9
(3,462 Views)

Hi,

 

Can you please specify, what would is myrobot here, so I can connect the same information in my code? Or if you can share your snippet of code that will be nice.

 

Thanks,

Riddhi

0 Kudos
Message 9 of 9
(3,458 Views)