Skip to content

Commit db43fd2

Browse files
committed
Fix internal shared assemblies with static mapping.
1 parent fadfc13 commit db43fd2

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

src/Components/Components/src/PersistentState/PersistentServicesRegistry.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,28 @@ public PropertiesAccessor([DynamicallyAccessedMembers(LinkerFlags.Component)] Ty
206206

207207
public (string, Type)[] KeyTypePairs => _cachedKeysForService;
208208

209+
// Mapping for internal classes bundled in different assemblies during prerendering and WASM rendering.
210+
private static readonly Dictionary<string, string> _canonicalMap = new(StringComparer.OrdinalIgnoreCase)
211+
{
212+
{ "Microsoft.AspNetCore.Components.Endpoints", "Microsoft.AspNetCore.Components" },
213+
{ "Microsoft.AspNetCore.Components.WebAssembly", "Microsoft.AspNetCore.Components" }
214+
};
215+
209216
private static string ComputeKey(Type keyType, string propertyName)
210217
{
211218
// This happens once per type and property combo, so allocations are ok.
212219
var assemblyName = keyType.Assembly.FullName;
220+
var assemblySimpleName = keyType.Assembly.GetName().Name ?? "";
221+
if (_canonicalMap.TryGetValue(assemblySimpleName, out var canonicalAssembly))
222+
{
223+
assemblyName = canonicalAssembly;
224+
}
225+
213226
var typeName = keyType.FullName;
214-
var input = Encoding.UTF8.GetBytes(string.Join(".", assemblyName, typeName, propertyName));
215-
return Convert.ToBase64String(SHA256.HashData(input));
227+
var inputString = string.Join(".", assemblyName, typeName, propertyName);
228+
var input = Encoding.UTF8.GetBytes(inputString);
229+
var hash = SHA256.HashData(input);
230+
return Convert.ToBase64String(hash);
216231
}
217232

218233
internal static IEnumerable<PropertyInfo> GetCandidateBindableProperties(

src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private static void InitializeResourceCollection(HttpContext httpContext)
149149
var resourceCollectionProvider = resourceCollectionUrl != null ? httpContext.RequestServices.GetService<ResourceCollectionProvider>() : null;
150150
if (resourceCollectionUrl != null && resourceCollectionProvider != null)
151151
{
152-
resourceCollectionProvider.SetResourceCollectionUrl(resourceCollectionUrl.Url);
152+
resourceCollectionProvider.ResourceCollectionUrl = resourceCollectionUrl.Url;
153153
resourceCollectionProvider.SetResourceCollection(resourceCollection ?? ResourceAssetCollection.Empty);
154154
}
155155
}

src/Components/Shared/src/ResourceCollectionProvider.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,23 @@ internal class ResourceCollectionProvider
1717
public string? ResourceCollectionUrl
1818
{
1919
get => _url;
20-
set => _url = value;
20+
set
21+
{
22+
if (_url != null)
23+
{
24+
throw new InvalidOperationException("The resource collection URL has already been set.");
25+
}
26+
_url = value;
27+
}
2128
}
29+
2230
private ResourceAssetCollection? _resourceCollection;
2331
private readonly IJSRuntime _jsRuntime;
2432
public ResourceCollectionProvider(IJSRuntime jsRuntime)
2533
{
2634
_jsRuntime = jsRuntime;
2735
}
2836

29-
[MemberNotNull(nameof(_url))]
30-
internal void SetResourceCollectionUrl(string url)
31-
{
32-
if (_url != null)
33-
{
34-
throw new InvalidOperationException("The resource collection URL has already been set.");
35-
}
36-
_url = url;
37-
}
38-
3937
internal async Task<ResourceAssetCollection> GetResourceCollection()
4038
{
4139
_resourceCollection = _resourceCollection ??= await LoadResourceCollection();
@@ -58,6 +56,8 @@ private async Task<ResourceAssetCollection> LoadResourceCollection()
5856

5957
var module = await _jsRuntime.InvokeAsync<IJSObjectReference>("import", _url);
6058
var result = await module.InvokeAsync<ResourceAsset[]>("get");
61-
return result == null ? ResourceAssetCollection.Empty : new ResourceAssetCollection(result);
59+
var collection = result == null ? ResourceAssetCollection.Empty : new ResourceAssetCollection(result);
60+
var asset = collection["BasicTestApp.styles.css"];
61+
return collection;
6262
}
6363
}

0 commit comments

Comments
 (0)