microsoft / vs-servicehub

The service broker libraries used by Visual Studio to exchange intra- and inter-process services
MIT License
20 stars 8 forks source link

ISB001 misfires on proxy fields that *are* disposed #214

Open AArnott opened 3 months ago

AArnott commented 3 months ago
        private ITerminalService terminalService;

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            foreach (var token in profferTokens)
                token?.Dispose();

            this.serviceBrokerClient?.Dispose();
            (this.terminalService as IDisposable)?.Dispose();
        }

The field is disposed, but the analyzer still emits this: error ISB001: The proxy stored in "LinuxConnectionManagerPackage.terminalService" must be disposed by an IDisposable.Dispose or Dispose(bool) method on the "LinuxConnectionManagerPackage" type.

AArnott commented 3 months ago

Luca also reported:

I hit this as well, had to explicitly suppress this warning in code, e.g.:

    internal class RenameRefactorCommand : IVsPreviewChangesEngine, IDisposable
    {
        line110: private readonly Microsoft.VisualStudio.Threading.AsyncLazy<ServiceBrokerClient> serviceBrokerClientLazy;

        void IDisposable.Dispose()
        {
            this.serviceBrokerClientLazy.DisposeValue();
        }
    }

C:\vs\src\vc\designtime\Managed\Rename.cs(110,90): error ISB001: The proxy stored in "RenameRefactorCommand.serviceBrokerClientLazy" must be disposed by an IDisposable.Dispose or Dispose(bool) method on the "RenameRefactorCommand" type. (https://github.com/microsoft/vs-servicehub/blob/3423437139210283925dbc2462d5637c9abad978/doc/analyzers/ISB001.md) [C:\vs\src\vc\designtime\Managed\dtmanaged_21vxelbh_wpftmp.csproj]