diff --git a/src/OpenTelemetry/Internal/ActivityInstrumentationHelper.cs b/src/OpenTelemetry/Internal/ActivityInstrumentationHelper.cs index 5a97e5fc2f6..d6124809b0b 100644 --- a/src/OpenTelemetry/Internal/ActivityInstrumentationHelper.cs +++ b/src/OpenTelemetry/Internal/ActivityInstrumentationHelper.cs @@ -16,6 +16,7 @@ using System.Diagnostics; using System.Linq.Expressions; +using System.Reflection; #pragma warning restore IDE0005 namespace OpenTelemetry.Instrumentation @@ -29,7 +30,8 @@ private static Action CreateActivitySourceSetter() { ParameterExpression instance = Expression.Parameter(typeof(Activity), "instance"); ParameterExpression propertyValue = Expression.Parameter(typeof(ActivitySource), "propertyValue"); - var body = Expression.Assign(Expression.Property(instance, "Source"), propertyValue); + PropertyInfo sourcePropertyInfo = typeof(Activity).GetProperty("Source"); + var body = Expression.Assign(Expression.Property(instance, sourcePropertyInfo), propertyValue); return Expression.Lambda>(body, instance, propertyValue).Compile(); } @@ -37,7 +39,8 @@ private static Action CreateActivityKindSetter() { ParameterExpression instance = Expression.Parameter(typeof(Activity), "instance"); ParameterExpression propertyValue = Expression.Parameter(typeof(ActivityKind), "propertyValue"); - var body = Expression.Assign(Expression.Property(instance, "Kind"), propertyValue); + PropertyInfo kindPropertyInfo = typeof(Activity).GetProperty("Kind"); + var body = Expression.Assign(Expression.Property(instance, kindPropertyInfo), propertyValue); return Expression.Lambda>(body, instance, propertyValue).Compile(); } } diff --git a/test/OpenTelemetry.AotCompatibility.Tests/AotCompatibilityTests.cs b/test/OpenTelemetry.AotCompatibility.Tests/AotCompatibilityTests.cs index f9c40b6fc93..78ef604fcad 100644 --- a/test/OpenTelemetry.AotCompatibility.Tests/AotCompatibilityTests.cs +++ b/test/OpenTelemetry.AotCompatibility.Tests/AotCompatibilityTests.cs @@ -85,7 +85,7 @@ public void EnsureAotCompatibility() Assert.True(process.ExitCode == 0, "Publishing the AotCompatibility app failed. See test output for more details."); var warnings = expectedOutput.ToString().Split('\n', '\r').Where(line => line.Contains("warning IL")); - Assert.Equal(58, warnings.Count()); + Assert.Equal(48, warnings.Count()); } } }