chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
I just installed TM 5.3.4, but I was having the same issue in 4.3.2. Some tests create a Form that has a tool strip.

I can run a test that creates this Form without mocking anything, and the test runs fine; if mocking has already started, the test fails.

The creation of the Form fails with this exception:
Test method Tests.CreateReviewControllerTest.OpenReviewTestOK threw exception: System.InvalidCastException: Unable to cast object of type 'System.Windows.Forms.LabelImageIndexer' to type 'System.Windows.Forms.ImageList'..

At least the former type is an internal type. The exception is happening when the ToolStripDropDownMenu is creating its Up and Down scroll buttons; it's totally internal.

I noticed this in the debug output:

A first chance exception of type 'System.InvalidCastException' occurred in System.Windows.Forms.dll
A first chance exception of type 'System.InvalidCastException' occurred in TypeMock.dll

So I think something in TypeMock is causing the framework to blow up.

I have run with and without code coverage, I get the same results.

EDIT: This is VS2005, .NET 2.0 SP 2.
asked by jeffozvold (1.4k points)

4 Answers

0 votes
Hi,

It is interesting, it might be a bug. Can you please post code that reproduces this exception?

Best Regards,
Elisha
Typemock Support
answered by Elisha (12k points)
0 votes
I tried developing a small test project with things that should cause it, but I can't reproduce it outside the original solution. I can send you the solution zipped up, because it is not extremely large, or I can send you a log.
answered by jeffozvold (1.4k points)
0 votes
Hi,

Let's take it offline and I'll investigate it with the repro solution.

Best Regards,
Elisha
Typemock Support
answered by Elisha (12k points)
0 votes
All,

To follow up our offline handling of this issue: the root cause for this is a bug with Natural Mocks when recording initialization of form constructors, and handling their static constructor. This creates an issue when creating another form later in the test.

As a work around I strongly recommend using the AAA API which is more powerful, readable and updated more frequently. If you must use the older APIs (strictly .NET 2.0 environment), use Reflective Mocks to create future mocks of forms in these situations.

Doron
Typemock Support
answered by doron (17.2k points)
...