azure-devops-dotnet-samples icon indicating copy to clipboard operation
azure-devops-dotnet-samples copied to clipboard

Disposed Exceptions

Open wjdavis5 opened this issue 4 years ago • 0 comments

Currently the clients implement IDisposable, which indicates to the user that they should be disposing of these objects after they have been used.

However doing so causes you to start receiving ObjectDisposedExceptions on further attempts to get a new client and then use it. Here is code to reproduce

static async Task Main(string[] args)
        {
            var creds = new VssBasicCredential("", "PAT");
            var conn = new VssConnection(new Uri("https://org.visualstudio.com"),creds);
            using (var git1 = await conn.GetClientAsync<GitHttpClient>())
            {
                var item = await git1.GetItemAsync("PROJECT", "REPO", "/File.json", null, null,
                    null, null, true, new GitVersionDescriptor() {Version = "master"}, true);
            }

            using (var git2 = await conn.GetClientAsync<GitHttpClient>())
            {
                var item = await git2.GetItemAsync("PROJECT", "REPO", "/File.json", null, null,
                    null, null, true, new GitVersionDescriptor() { Version = "master" }, true);
            }

        }

I see this mentioned in #266 - but to me this is either a bug or a design flaw.

Can you please clarify when these objects should be disposed?

wjdavis5 avatar Jun 16 '20 15:06 wjdavis5