protected void Run(string type, string method) { lock (lockObject) { using (var vld = new VisualLeakDetector()) { try { // vowpalwabbit\x64\Debug\cs_leaktest.dll var basePath = Path.GetDirectoryName(typeof(VisualLeakDetector).Assembly.Location); var handle = LoadLibrary(basePath + @"\\VowpalWabbitCore.dll"); var appDomain = AppDomain.CreateDomain("Test1"); try { ITestRunner test1 = (ITestRunner)appDomain.CreateInstanceFromAndUnwrap(basePath + @"\\cs_unittest.dll", "cs_unittest.TestRunner"); Environment.CurrentDirectory = basePath + @"\..\..\..\test"; var result = test1.Run(type, method); if (result != null) { // check for exception marker var index = result.IndexOf("#-#-#-#-#-#-#"); if (index == -1) { Assert.Fail(result); } throw new CustomException(result.Substring(0, index), result.Substring(index + 13)); } } finally { AppDomain.Unload(appDomain); } try { FreeLibrary(handle); FreeLibrary(handle); vld.ReportLeaks(); var message = string.Concat(vld.Messages.Select(t => t.Item2)); var blocks = message.Split(new[] { "---------- Block " }, StringSplitOptions.None) .Where(block => Regex.IsMatch(block, "^\\d+ at")) .ToList(); Assert.AreEqual(0, blocks.Count, string.Join("\n", blocks)); } finally { LoadLibrary(basePath + @"\VowpalWabbitCore.dll"); } } finally { vld.MarkAllLeaksAsReported(); } } } }