Skip to content

Commit 3debf85

Browse files
committed
Fix annotations
1 parent cf9bec7 commit 3debf85

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

src/Components/WebAssembly/WebAssembly/src/Rendering/WebAssemblyRenderer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public WebAssemblyRenderer(IServiceProvider serviceProvider, ILoggerFactory logg
3333
DefaultWebAssemblyJSRuntime.Instance.OnUpdateRootComponents += OnUpdateRootComponents;
3434
}
3535

36+
[UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "These are root components which belong to the user and are in assemblies that don't get trimmed.")]
3637
private void OnUpdateRootComponents(OperationDescriptor[] operations)
3738
{
3839
for (var i = 0; i < operations.Length; i++)

src/Components/WebAssembly/WebAssembly/src/Services/DefaultWebAssemblyJSRuntime.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ internal sealed partial class DefaultWebAssemblyJSRuntime : WebAssemblyJSRuntime
2727
[DynamicDependency(nameof(EndInvokeJS))]
2828
[DynamicDependency(nameof(BeginInvokeDotNet))]
2929
[DynamicDependency(nameof(ReceiveByteArrayFromJS))]
30+
[DynamicDependency(nameof(UpdateRootComponentsCore))]
3031
private DefaultWebAssemblyJSRuntime()
3132
{
3233
ElementReferenceContext = new WebElementReferenceContext(this);
@@ -97,8 +98,8 @@ private static void UpdateRootComponentsCore(string operationsJson)
9798
}
9899

99100
[DynamicDependency(JsonSerialized, typeof(RootComponentOperation))]
100-
[DynamicDependency(Component, typeof(OperationDescriptor))]
101101
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The correct members will be preserved by the above DynamicDependency")]
102+
[SuppressMessage("Trimming", "IL2072:Target parameter argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The return value of the source method does not have matching annotations.", Justification = "Types in that cache are components from the user assembly which are never trimmed.")]
102103
internal static OperationDescriptor[] DeserializeOperations(string operationsJson)
103104
{
104105
var deserialized = JsonSerializer.Deserialize<RootComponentOperation[]>(
@@ -137,23 +138,15 @@ internal static OperationDescriptor[] DeserializeOperations(string operationsJso
137138
{
138139
throw new InvalidOperationException($"The component operation of type '{operation.Type}' requires a '{nameof(operation.SelectorId)}' to be specified.");
139140
}
140-
componentType = ResolveComponentType(operation);
141+
componentType = Instance._rootComponentCache.GetRootComponent(operation.Marker!.Value.Assembly!, operation.Marker.Value.TypeName!)
142+
?? throw new InvalidOperationException($"Root component type '{operation.Marker.Value.TypeName}' could not be found in the assembly '{operation.Marker.Value.Assembly}'.");
141143
}
142144

143145
var parameters = DeserializeComponentParameters(operation.Marker.Value);
144146
operations[i] = new(operation, componentType, parameters);
145147
}
146148

147149
return operations;
148-
149-
[return: DynamicallyAccessedMembers(Component)]
150-
[SuppressMessage("Trimming", "IL2073:Target method return value does not satisfy 'DynamicallyAccessedMembersAttribute' requirements. The return value of the source method does not have matching annotations.", Justification = "The dynamic dependency above makes sure the type is" +
151-
"preserved.")]
152-
static Type ResolveComponentType(RootComponentOperation operation)
153-
{
154-
return Instance._rootComponentCache.GetRootComponent(operation.Marker!.Value.Assembly!, operation.Marker.Value.TypeName!)
155-
?? throw new InvalidOperationException($"Root component type '{operation.Marker.Value.TypeName}' could not be found in the assembly '{operation.Marker.Value.Assembly}'.");
156-
}
157150
}
158151

159152
static ParameterView DeserializeComponentParameters(ComponentMarker marker)
@@ -188,7 +181,7 @@ internal readonly struct OperationDescriptor
188181
{
189182
public OperationDescriptor(
190183
RootComponentOperation operation,
191-
[DynamicallyAccessedMembers(Component)] Type? componentType,
184+
Type? componentType,
192185
ParameterView parameters)
193186
{
194187
Operation = operation;
@@ -198,12 +191,11 @@ public OperationDescriptor(
198191

199192
public RootComponentOperation Operation { get; }
200193

201-
[DynamicallyAccessedMembers(Component)]
202194
public Type? ComponentType { get; }
203195

204196
public ParameterView Parameters { get; }
205197

206-
public void Deconstruct(out RootComponentOperation operation, [DynamicallyAccessedMembers(Component)] out Type? componentType, out ParameterView parameters)
198+
public void Deconstruct(out RootComponentOperation operation, out Type? componentType, out ParameterView parameters)
207199
{
208200
operation = Operation;
209201
componentType = ComponentType;

src/Components/WebAssembly/WebAssembly/src/Services/InternalJSImportMethods.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using System.Globalization;
56
using System.Runtime.InteropServices.JavaScript;
67
using Microsoft.AspNetCore.Components.Web;
@@ -17,6 +18,7 @@ private InternalJSImportMethods() { }
1718
public string GetPersistedState()
1819
=> GetPersistedStateCore();
1920

21+
[UnconditionalSuppressMessage("Trimming", "IL2067", Justification = "These are root components which belong to the user and are in assemblies that don't get trimmed.")]
2022
public static async Task<RootComponentMapping[]> GetInitialComponentUpdate()
2123
{
2224
var components = await InternalJSImportMethods.GetInitialUpdateCore();

src/Components/test/testassets/Components.WasmMinimal/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
Assembly.Load(nameof(TestContentPackage));
1010

11-
1211
var builder = WebAssemblyHostBuilder.CreateDefault(args);
1312
builder.Services.AddSingleton<AsyncOperationService>();
1413

0 commit comments

Comments
 (0)