CA2000 is a warning regarding the IDisposable interface:
CA2000 : Microsoft.Reliability : In method \'ImportProcessor.GetContext(string)\', call Sys
What CA2000 is complaining about here is that the variable could be "orphaned" in an undisposed state if there's an exception while attempting to add it to the cache. To address the problem thoroughly, you could add a try/catch as follows (the newContext
variable is used only so that CA2000 can detect the fix):
public RegionContext GetContext(string regionCode)
{
RegionContext rc = null;
if (!this.contextCache.TryGetValue(regionCode.ToUpper(), out rc))
{
RegionContext newContext = new RegionContext(regionCode);
try
{
this.contextCache.Add(regionCode.ToUpper(), newContext);
}
catch
{
newContext.Dispose();
throw;
}
rc = newContext;
}
return rc;
}
Personally, I find this sort of thing to be somewhat ridiculous overkill in most cases, but ymmv...