microsoft / azure-devops-dotnet-samples

.NET/C# samples for integrating with Azure DevOps Services and Azure DevOps Server
https://docs.microsoft.com/azure/devops/integrate
MIT License
519 stars 511 forks source link

Disposed Exceptions #287

Open wjdavis5 opened 4 years ago

wjdavis5 commented 4 years ago

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?