NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

'Invalid cast exception' thrown when AutoCompleteStringCollection assigned to TextBox's AutoCompleteCustomSource property

Solved!
Go to solution

Hi,

I have built a .NET C# wrapper around the User Management module of TestStand.

When the application works as a standalone Windows Application, there are no exceptions or errors thrown. However, when the dll is integrated with TestStand and called from the FrontEndCallbacks sequence file, I am thrown an 'Invalid cast' exception when AutoCompleteStringCollection is assigned to a textBox's AutoCompleteCustomSource property.

As previously stated, it works perfectly fine when it's a stand alone application. I am at a loss to figure why this is happening. I would really appreciate if anybody could throw some light on this behaviour.

 

Thanks

Arun 

0 Kudos
Message 1 of 5
(4,934 Views)

Hi Arun,

 

What do you mean by standalone application? Does it mean using the DLL seperately in some other application like LabVIEW?

 

Invalid cast exception can be due to TestStand not accepting the data type associated coming from/ required by your DLL.

 

Can you share your DLL and the sequence file so that me as well as other user can have more information?

 

Regards

Vaibhav

.......^___________________^
....../ '---_BOT ____________ ]
...../_==O;;;;;;;;_______.:/
.....),---.(_(____)/.....
....// (..) ),----/....
...//____//......
..//____//......
.//____//......
..-------
0 Kudos
Message 2 of 5
(4,906 Views)

Hi Vaibhav,

 

By stand alone, I mean that the application can also work as a windows application. However, by making the application into a dll, the application is invoked through TestStand.

Unfortunately, I cannot the share the original dll for security purposes. However, I have posted a sample dll and the associated pdb file along with the  sequence file.Hope it helps.

 

Regards

Arun

 

 

 

0 Kudos
Message 3 of 5
(4,878 Views)
Solution
Accepted by topic author Arun Padmanabhan

Thank you for posting your example. The problem appears to be caused by the fact that your form is created in a TestStand execution thread which uses the MTA COM threading model. .NET Windows forms should always be created in threads marked with the STA threading model. Your standalone application no doubt uses the STAThread attribute. Here are a couple of references (FxCop Rule, STAThread)

 

You can work around this problem by creating a new STA thread in TestStand using a sequence call step. Set the Execution Options to Use New Thread and check the Use Single-Threaded Apartment checkbox.

Message 4 of 5
(4,870 Views)
Thanks Erik. It works now.
0 Kudos
Message 5 of 5
(4,835 Views)