Skip to content

Commit 56855bc

Browse files
committed
Unload module raise exception
1 parent 28aa07f commit 56855bc

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/coverlet.collector/InProcDataCollection/CoverletInProcDataCollector.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Reflection;
3+
using coverlet.collector.Resources;
34
using Coverlet.Collector.Utilities;
45
using Coverlet.Core.Instrumentation;
56
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
@@ -29,23 +30,25 @@ public void TestSessionEnd(TestSessionEndArgs testSessionEndArgs)
2930
{
3031
Type injectedInstrumentationClass = GetInstrumentationClass(assembly);
3132
if (injectedInstrumentationClass is null)
33+
{
3234
continue;
33-
34-
var unloadModule = injectedInstrumentationClass.GetMethod(nameof(ModuleTrackerTemplate.UnloadModule), new[] { typeof(object), typeof(EventArgs) });
35-
if (unloadModule is null)
36-
continue;
35+
}
3736

3837
try
3938
{
39+
var unloadModule = injectedInstrumentationClass.GetMethod(nameof(ModuleTrackerTemplate.UnloadModule), new[] { typeof(object), typeof(EventArgs) });
4040
unloadModule.Invoke(null, new[] { null, EventArgs.Empty });
4141
}
4242
catch(Exception ex)
4343
{
44-
// Ignore exceptions and continue with the unload
45-
if (EqtTrace.IsWarningEnabled)
44+
// Throw any exception if unload fails
45+
if (EqtTrace.IsErrorEnabled)
4646
{
47-
EqtTrace.Warning("{0}: Failed to unload module with error: {1}", CoverletConstants.InProcDataCollectorName, ex);
47+
EqtTrace.Error("{0}: Failed to unload module with error: {1}", CoverletConstants.InProcDataCollectorName, ex);
4848
}
49+
50+
string errorMessage = string.Format(Resources.FailedToUnloadModule, CoverletConstants.InProcDataCollectorName);
51+
throw new CoverletDataCollectorException(errorMessage, ex);
4952
}
5053
}
5154
}

src/coverlet.collector/Resources/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/coverlet.collector/Resources/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<data name="FailedToSaveCoverageReport" xml:space="preserve">
130130
<value>{0}: Failed to save coverage report '{1}' in directory '{2}'</value>
131131
</data>
132+
<data name="FailedToUnloadModule" xml:space="preserve">
133+
<value>{0}: Failed to unload module</value>
134+
</data>
132135
<data name="InstrumentationException" xml:space="preserve">
133136
<value>{0}: Failed to instrument modules</value>
134137
</data>

0 commit comments

Comments
 (0)