Developer
Developer

Reputation: 888

Unable to cast object of type 'Rally.RestApi.RallyRestApi' to type 'System.IDisposable'

I am using Rally Web API, I am authenticating Rally web API class below :

 public class FetchRally
  {
    RallyRestApi restApi;
    public FetchRally()
    {
        restApi = new RallyRestApi(webServiceVersion: "v2.0");
        restApi.Authenticate(HttpContext.Current.Session["Username"].ToString(), HttpContext.Current.Session["Password"].ToString(), "https://rally1.rallydev.com/", allowSSO: false);
    }

    public void GetMethod(){
       try{
        //Do Something
        }
       catch{}
       finally
        {
            ((IDisposable)restApi).Dispose(); // Getting error
        }
       }

    }

I want to dispose or kill the object after method code execution, but in run time facing below error:

Unable to cast object of type 'Rally.RestApi.RallyRestApi' to type 'System.IDisposable'.

Can anyone please help me on this.

Upvotes: 0

Views: 589

Answers (1)

Roman
Roman

Reputation: 12171

You can't cast RallyRestApi to IDisposable because this class doesn't implement IDisposable interface - RallyRestApi Class

If you don't need this object after method executes:

finally
{
    restApi = null;
}

And garbage collector will destroy this object during next Garbage Collection if you don't have any other references to this object.

Upvotes: 1

Related Questions