This question is locked. New answers and comments are not allowed.
Hello,
I create a VirtualQueryableCollectionView<T> in my view model's constructor and store a reference in a private instance field. Code analysis flags 'CA2000: Dispose objects before losing scope' for the line in the constructor where the VirtualQueryableCollectionView<T> is created and assigned to the private instance field. The full message is:
CA2000 : Microsoft.Reliability : In method 'EntriesViewModel.EntriesViewModel(ILogbookViewerContext, IAppService, ExceptionManager)', object '<>g__initLocal0' is not disposed along all exception paths. Call System.IDisposable.Dispose on object '<>g__initLocal0' before all references to it are out of scope.
So then I noticed that VirtualQueryableCollectionView<T> implements IDisposable in its base class QueryableCollectionView. Although strange that it mentions an object <>g__initLocal0 instead of VirtualQueryableCollectionView<T>. I would have also expected 'CA1001: Types that own disposable fields should be disposable' to be flagged instead of 'CA2000: Dispose objects before losing scope' with the full message
CA1001 : Microsoft.Design : Implement IDisposable on 'EntriesViewModel' because it creates members of the following IDisposable types: 'VirtualQueryableCollectionView<T>'. If 'EntriesViewModel' has previously shipped, adding new members that implement IDisposable to this type is considered a breaking change to existing consumers.
But that's not what I got. In any case I implemented IDisposable in my view model to dispose of the VirtualQueryableCollectionView<T>. Unfortunately that did not make the 'CA2000: Dispose objects before losing scope' go away. Anybody any ideas?
Remco
I create a VirtualQueryableCollectionView<T> in my view model's constructor and store a reference in a private instance field. Code analysis flags 'CA2000: Dispose objects before losing scope' for the line in the constructor where the VirtualQueryableCollectionView<T> is created and assigned to the private instance field. The full message is:
CA2000 : Microsoft.Reliability : In method 'EntriesViewModel.EntriesViewModel(ILogbookViewerContext, IAppService, ExceptionManager)', object '<>g__initLocal0' is not disposed along all exception paths. Call System.IDisposable.Dispose on object '<>g__initLocal0' before all references to it are out of scope.
So then I noticed that VirtualQueryableCollectionView<T> implements IDisposable in its base class QueryableCollectionView. Although strange that it mentions an object <>g__initLocal0 instead of VirtualQueryableCollectionView<T>. I would have also expected 'CA1001: Types that own disposable fields should be disposable' to be flagged instead of 'CA2000: Dispose objects before losing scope' with the full message
CA1001 : Microsoft.Design : Implement IDisposable on 'EntriesViewModel' because it creates members of the following IDisposable types: 'VirtualQueryableCollectionView<T>'. If 'EntriesViewModel' has previously shipped, adding new members that implement IDisposable to this type is considered a breaking change to existing consumers.
But that's not what I got. In any case I implemented IDisposable in my view model to dispose of the VirtualQueryableCollectionView<T>. Unfortunately that did not make the 'CA2000: Dispose objects before losing scope' go away. Anybody any ideas?
Remco