Я получаю это сообщение для строки 84 и строки 85 (две, сложенные с использованием строк):
CA2000 :Microsoft.Reliability :В методе 'RavenDataAccess.GetRavenDatabase()' объект '<>g_initLocal9' расположен не по всем путям исключений. Вызовите System.IDisposable.Dispose для объекта '<>g_initLocal9', прежде чем все ссылки на него будут вне области видимости.
DocumentStore реализует IDisposable.
Почему? Как еще я могу избавиться от объектов DocumentStore? Они создаются в блоке using, и я удаляю их в своем блоке catch. Как это исправить?
private static IDocumentStore GetRavenDatabase()
{
Shards shards = new Shards();
try
{
using (DocumentStore docStore1 = new DocumentStore { Url = ConfigurationManager.AppSettings["RavenShard1"] }) // Line 84
using (DocumentStore docStore2 = new DocumentStore { Url = ConfigurationManager.AppSettings["RavenShard2"] }) // Line 85
{
shards.Add(docStore1);
shards.Add(docStore2);
}
using (ShardedDocumentStore documentStore = new ShardedDocumentStore(new ShardStrategy(), shards))
{
documentStore.Initialize();
IndexCreation.CreateIndexes(typeof(RavenDataAccess).Assembly, documentStore);
return documentStore;
}
}
catch
{
shards.ForEach(docStore => docStore.Dispose());
throw;
}
}