Skip to content

Commit 7feb550

Browse files
authored
Merge pull request #302 from ViktorHofer/GuardInstrumentation
Guard instrumentation exclude Interlocked
2 parents 0d285b1 + f68473b commit 7feb550

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/coverlet.core/Instrumentation/Instrumenter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ private void InstrumentModule()
7171
{
7272
resolver.AddSearchDirectory(Path.GetDirectoryName(_module));
7373
var parameters = new ReaderParameters { ReadSymbols = true, AssemblyResolver = resolver };
74-
if (Path.GetFileNameWithoutExtension(_module) == "System.Private.CoreLib")
74+
bool isCoreLib = Path.GetFileNameWithoutExtension(_module) == "System.Private.CoreLib";
75+
if (isCoreLib)
7576
{
7677
parameters.MetadataImporterProvider = new CoreLibMetadataImporterProvider();
7778
}
@@ -92,6 +93,8 @@ private void InstrumentModule()
9293
{
9394
var actualType = type.DeclaringType ?? type;
9495
if (!actualType.CustomAttributes.Any(IsExcludeAttribute)
96+
// Instrumenting Interlocked which is used for recording hits would cause an infinite loop.
97+
&& (!isCoreLib || actualType.FullName != "System.Threading.Interlocked")
9598
&& !InstrumentationHelper.IsTypeExcluded(_module, actualType.FullName, _excludeFilters)
9699
&& InstrumentationHelper.IsTypeIncluded(_module, actualType.FullName, _includeFilters))
97100
InstrumentType(type);

0 commit comments

Comments
 (0)