How to fix a CA2000 IDisposable C# compiler warning, when using a global cache
问题 CA2000 is a warning regarding the IDisposable interface: CA2000 : Microsoft.Reliability : In method 'ImportProcessor.GetContext(string)', call System.IDisposable.Dispose on object 'c' before all references to it are out of scope. My method is used to store a cache of context like so: public class RegionContext : IDisposable { /* Implement Dispose() here */ } private Dictionary<string, RegionContext> contextCache = new ..... (); public RegionContext GetContext(string regionCode) {