Skip to content

Commit 47ce518

Browse files
committed
Resolve ILLink warnings in System.Diagnostics.DiagnosticSource (Round 1)
Contributes to #45623
1 parent 1a95b65 commit 47ce518

3 files changed

Lines changed: 8 additions & 15 deletions

File tree

src/libraries/System.Diagnostics.DiagnosticSource/src/ILLink/ILLink.Suppressions.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,5 @@
77
<property name="Scope">member</property>
88
<property name="Target">M:System.Diagnostics.DiagnosticSourceEventSource.FilterAndTransform.MakeImplicitTransforms(System.Type)</property>
99
</attribute>
10-
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
11-
<argument>ILLink</argument>
12-
<argument>IL2070</argument>
13-
<property name="Scope">member</property>
14-
<property name="Target">M:System.Diagnostics.DiagnosticSourceEventSource.TransformSpec.PropertySpec.PropertyFetch.FetcherForProperty(System.Type,System.String)</property>
15-
</attribute>
1610
</assembly>
17-
</linker>
11+
</linker>

src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
44
<CLSCompliant>false</CLSCompliant>
@@ -29,8 +29,6 @@
2929
<None Include="DiagnosticSourceUsersGuide.md" />
3030
</ItemGroup>
3131
<ItemGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) != '.NETCoreApp'">
32-
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicDependencyAttribute.cs" />
33-
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" />
3432
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs" />
3533
</ItemGroup>
3634
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard1.1'">

src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,9 +1331,6 @@ public PropertyFetch(Type? type)
13311331
/// <summary>
13321332
/// Create a property fetcher for a propertyName
13331333
/// </summary>
1334-
[DynamicDependency("#ctor(System.Type)", typeof(EnumeratePropertyFetch<>))]
1335-
[DynamicDependency("#ctor(System.Type,System.Reflection.PropertyInfo)", typeof(RefTypedFetchProperty<,>))]
1336-
[DynamicDependency("#ctor(System.Type,System.Reflection.PropertyInfo)", typeof(ValueTypedFetchProperty<,>))]
13371334
public static PropertyFetch FetcherForProperty(Type? type, string propertyName)
13381335
{
13391336
if (propertyName == null)
@@ -1382,10 +1379,14 @@ public static PropertyFetch FetcherForProperty(Type? type, string propertyName)
13821379
}
13831380
else
13841381
{
1385-
PropertyInfo? propertyInfo = typeInfo.GetDeclaredProperty(propertyName);
1382+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:RequiresUnreferencedCode",
1383+
Justification = "If the property is trimmed, a message gets logged to inform the user.")]
1384+
static PropertyInfo? GetProperty(TypeInfo type, string name) => type.GetDeclaredProperty(name);
1385+
1386+
PropertyInfo? propertyInfo = GetProperty(typeInfo, propertyName);
13861387
if (propertyInfo == null)
13871388
{
1388-
Logger.Message($"Property {propertyName} not found on {type}");
1389+
Logger.Message($"Property {propertyName} not found on {type}. Ensure the name is spelled correctly. If you published the application with PublishTrimmed=true, ensure the property was not trimmed away.");
13891390
return new PropertyFetch(type);
13901391
}
13911392
// Delegate creation below is incompatible with static properties.

0 commit comments

Comments
 (0)