Click here to Skip to main content
15,741,818 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am getting the below error while automating a test case . Can anyone pleas help me .
System.ObjectDisposedException: 'Cannot access a disposed object.

This exception was originally thrown at this call stack:
    [External Code]
    MedNavigator.PagesObjects.CompleteRequestProcessPage.selectTemplateType.get() in CompleteRequestProcessPage.cs
    MedNavigator.PagesObjects.CompleteRequestProcessPage.SelectTemplate() in CompleteRequestProcessPage.cs

What I have tried:

I have tried creating a new class but it didn't help me .
Updated 1-Aug-22 21:29pm

1 solution

You are trying to use an object that has had Dispose called on it because it wa no longer wanted. That releases all memory and resources allocated to the object and returns it to the Heap pool. Subsequent attempts to use the actual object by any means will cause an error.

The simplest way to generate the error is to create an instance of a class inside a using block, and keep a copy of it:
private MyClass theInstanceInQuestion;
   using (MyClass instance = new MyClass)
      ... do something with the instance here ...
      theInstanceInQuestion = instance;
      } // At this point, instance is Disposed.
We can't tell you how to fix this: we have no access to your code or the test cases you are using - but somehow you have maintained a reference to an object that is Disposed and are trying to use it again!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900