Reputation: 2249
I didn't create the framework but I need to write test for it. The scenario...
When executing a method that relies on the registered object, my test sometimes fails because it has been garbage collected before i performed test to it.
Can I do something to prevent GC from collecting my WeakReference object?
NOTE: No changes should be done in the framework (BaseClass), only in my test class
Upvotes: 1
Views: 922
Reputation: 2249
Sorry, I found an answer to this... During testing you should make use of...
GC.KeepAlive(weakObject)
Full reference here.
http://defragdev.com/blog/?p=129
Upvotes: 1