InvalidOperationException thrown on event unsubscribe after changing from .NET framework 3.5 to 4.5

116 views
Skip to first unread message

Richard Foster

unread,
Nov 19, 2012, 3:12:26 PM11/19/12
to rhino...@googlegroups.com
I am starting on a new project, and the plan is to reuse several well-tested components from other projects, but rebuild them so the entire solution targets the same version of the .NET runtime.

After switching the legacy project from .NET framework version 3.5 to 4.5, several previously passing tests have started to fail, specifically by throwing an InvalidOperationException with the message "This action is invalid when the mock object is in a verified state". The exception is being triggered when a class unsubscribes from an event (in the case of the tests, one that is raised by a mock object) as part of the referencing object's "Dispose" processing.

The problem is seen using both RhinoMocks v3.6 (which was what the "legacy" component used previously) and v3.6.1.

1) Is unsubscribing from an event handler during the "Dispose" processing an appropriate thing to do?

2) Under normal (non-mock) circumstances, is there any situation in which removing a subscription to an event would cause an exception?

3) What changed in the event processing which may have led to this failure?

Regards,
Richard

haifisch

unread,
Nov 20, 2012, 2:59:13 AM11/20/12
to rhino...@googlegroups.com
Hi Richard,

very strange - at least at my trunk (https://github.com/alaendle/rhino-mocks) all existing Rhino.Mocks tests are succeeding if I switch only the test project to .net 4.5.
Could you please provide an example of a test running under .net 3.5, but fails on .net 4.5 - this would make error tracking a lot easier ;-)

Br,

Andreas

Richard Foster

unread,
Nov 20, 2012, 7:38:45 AM11/20/12
to rhino...@googlegroups.com
If I can trigger the same situation from a stand-alone test, I certainly will provide an example. :-)

I'm 99% certain it's because of problems in our code... I just hoped someone might have had similar trouble and might be able to suggest why. (My suspicion is that it might be due to changes in the garbage collection resulting in things being disposed in a different order than previously.)

Regards,
Richard
Reply all
Reply to author
Forward
0 new messages