Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions src/coreclr/System.Private.CoreLib/CompatibilitySuppressions.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal static class RuntimeTypeMetadataUpdateHandler
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Clearing the caches on a Type isn't affected if a Type is trimmed, or has any of its members trimmed.")]
public static void ClearCache(Type[]? types)
{
RuntimeType.FilterDeletedMembers = true;

if (RequiresClearingAllTypes(types))
{
// TODO: This should ideally be in a QCall in the runtime. As written here:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,26 @@ private unsafe T[] GetListByName(string name, Span<byte> utf8Name, MemberListTyp
Debug.Fail("Invalid CacheType");
break;
}
return (T[])list;

if (RuntimeType.FilterDeletedMembers)
{
T[] sourceItems = (T[])list;
ListBuilder<T> nonDeletedList = default;

for (int i = 0; i < sourceItems.Length; i++)
{
if (!sourceItems[i].IsDefined(typeof(System.Runtime.CompilerServices.MetadataUpdateDeletedAttribute), true))
{
nonDeletedList.Add(sourceItems[i]);
}
}

return nonDeletedList.ToArray();
}
else
{
return (T[])list;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Console</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.ArraySignature</Target>
Expand Down Expand Up @@ -57,6 +53,14 @@
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.ConstantBooleanValueHandle</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.ConstantEnumValue</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.ConstantEnumValueHandle</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.ConstantByteArray</Target>
Expand Down Expand Up @@ -113,14 +117,6 @@
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.ConstantEnumArrayHandle</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.ConstantEnumValue</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.ConstantEnumValueHandle</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.ConstantHandleArray</Target>
Expand Down Expand Up @@ -657,10 +653,6 @@
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Metadata.NativeFormat.UInt64Collection</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.NativeFormat.TypeHashingAlgorithms</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Reflection.Core.AssemblyBinder</Target>
Expand Down Expand Up @@ -733,10 +725,6 @@
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.TypeSystem.LockFreeReaderHashtable`2</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.TypeSystem.LockFreeReaderHashtableOfPointers`2</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.Diagnostics.DebugAnnotations</Target>
Expand All @@ -747,11 +735,11 @@
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.FieldHandleInfo</Target>
<Target>T:System.MDArray</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.MDArray</Target>
<Target>T:System.FieldHandleInfo</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
Expand Down Expand Up @@ -818,41 +806,23 @@
<Target>T:System.Runtime.CompilerServices.StaticClassConstructionContext</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:System.Resources.ResourceManager.BaseNameField</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:System.Resources.ResourceSet.Reader</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Diagnostics.DiagnosticMethodInfo.#ctor(System.String,System.String,System.String)</Target>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.TypeSystem.LockFreeReaderHashtableOfPointers`2</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Reflection.MethodBase.GetParametersAsSpan</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.String.Trim(System.ReadOnlySpan{System.Char})</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.String.TrimEnd(System.ReadOnlySpan{System.Char})</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.String.TrimStart(System.ReadOnlySpan{System.Char})</Target>
<Target>M:System.Threading.Lock.#ctor(System.Boolean)</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:System.Threading.Lock.#ctor(System.Boolean)</Target>
<Target>M:System.Diagnostics.DiagnosticMethodInfo.#ctor(System.String,System.String,System.String)</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0008</DiagnosticId>
<Target>T:System.Collections.BitArray</Target>
<Left>ref/net10.0/System.Private.CoreLib.dll</Left>
<Right>lib/net10.0/System.Private.CoreLib.dll</Right>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.NativeFormat.TypeHashingAlgorithms</Target>
</Suppression>
</Suppressions>
</Suppressions>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- Type exposed publicly in implementation only for serialization purposes. -->
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:System.Collections.Specialized.ListDictionary.DictionaryNode</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,5 +1024,7 @@ private CheckValueStatus TryChangeType(ref object? value, ref bool copyBack)

return CheckValueStatus.ArgumentException;
}

internal static bool FilterDeletedMembers { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Reflection.Metadata.ApplyUpdate.Test
{
public class ReflectionDeleteMethod
{
public string Id { get; set;}

public string Name { get; set; }

public string FullName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Reflection.Metadata.ApplyUpdate.Test
{
public class ReflectionDeleteMethod
{
public string Id { get; set;}

public string Name { get; set; }

[System.Runtime.CompilerServices.MetadataUpdateDeleted]
public string FullName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>System.Runtime.Loader.Tests</RootNamespace>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<TestRuntime>true</TestRuntime>
<DeltaScript>deltascript.json</DeltaScript>
</PropertyGroup>
<ItemGroup>
<Compile Include="ReflectionDeleteMethod.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"changes": [
{"document": "ReflectionDeleteMethod.cs", "update": "ReflectionDeleteMethod_v1.cs"}
]
}

22 changes: 22 additions & 0 deletions src/libraries/System.Runtime.Loader/tests/ApplyUpdateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ namespace System.Reflection.Metadata
[Collection(nameof(DisableParallelization))]
public class ApplyUpdateTest
{
[ConditionalFact(typeof(ApplyUpdateUtil), nameof (ApplyUpdateUtil.IsSupported))]
void DeleteMethodTest()
{
ApplyUpdateUtil.TestCase(static () =>
{
var assm = typeof (ApplyUpdate.Test.ReflectionDeleteMethod).Assembly;

var t = assm.GetType("System.Reflection.Metadata.ApplyUpdate.Test.ReflectionDeleteMethod");
Assert.NotNull(t);

var mi = t.GetProperty("FullName");
Assert.NotNull(mi);

ApplyUpdateUtil.ApplyUpdate(assm);
ApplyUpdateUtil.ClearAllReflectionCaches();

// FullName should be filtered out now
mi = t.GetProperty("FullName");
Assert.Null(mi);
});
}

[ConditionalFact(typeof(ApplyUpdateUtil), nameof (ApplyUpdateUtil.IsSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/54617", typeof(PlatformDetection), nameof(PlatformDetection.IsBrowser), nameof(PlatformDetection.IsMonoAOT))]
void StaticMethodBodyUpdate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.StaticLambdaRegression\System.Reflection.Metadata.ApplyUpdate.Test.StaticLambdaRegression.csproj" />
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.ReflectionAddNewType\System.Reflection.Metadata.ApplyUpdate.Test.ReflectionAddNewType.csproj" />
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.ReflectionAddNewMethod\System.Reflection.Metadata.ApplyUpdate.Test.ReflectionAddNewMethod.csproj" />
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.ReflectionDeleteMethod\System.Reflection.Metadata.ApplyUpdate.Test.ReflectionDeleteMethod.csproj" />
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.GenericAddStaticField\System.Reflection.Metadata.ApplyUpdate.Test.GenericAddStaticField.csproj" />
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.GenericAddInstanceField\System.Reflection.Metadata.ApplyUpdate.Test.GenericAddInstanceField.csproj" />
<ProjectReference Include="ApplyUpdate\System.Reflection.Metadata.ApplyUpdate.Test.NewMethodThrows\System.Reflection.Metadata.ApplyUpdate.Test.NewMethodThrows.csproj" />
Expand Down
Loading