From 12e8f6526548055a42cc8ec3d71e36308e4b243d Mon Sep 17 00:00:00 2001 From: Patrick Simpson Date: Mon, 27 Feb 2017 12:36:17 +0100 Subject: [PATCH] Fix for undisposed wrapper. --- .../AcaciaZPushPlugin/UI/GABLookupControl.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/UI/GABLookupControl.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/UI/GABLookupControl.cs index 31cf925..e25783e 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/UI/GABLookupControl.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/UI/GABLookupControl.cs @@ -247,15 +247,17 @@ namespace Acacia.UI if (_gab?.Contacts != null) { // Begin GAB lookup, search on full name or username - ISearch search = _gab.Contacts.Search(); - search.AddField("urn:schemas:contacts:customerid").SetOperation(SearchOperation.Equal, username); - - // Fetch the result, if any. - // TODO: make a SearchOne method? - List users = new List(); - foreach (IContactItem result in search.Search(1)) + using (ISearch search = _gab.Contacts.Search()) { - return new GABUser(result.FullName, result.CustomerID); + search.AddField("urn:schemas:contacts:customerid").SetOperation(SearchOperation.Equal, username); + + // Fetch the result, if any. + List users = new List(); + using (IContactItem result = search.SearchOne()) + { + if (result != null) + return new GABUser(result.FullName, result.CustomerID); + } } }