dotnet / dotnet/aspnetcore

NET8 ResourceManagerStringLocalizerFactory not Work In ALC

Open
#55,121 0 comments 0 reactions 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Create method in source code
```
public IStringLocalizer Create(Type resourceSource)
{
Microsoft.AspNetCore.Shared.ArgumentNullThrowHelper.ThrowIfNull(resourceSource, "resourceSource");
if (!_localizerCache.TryGetValue(resourceSource.AssemblyQualifiedName, out var value))
{
TypeInfo typeInfo = resourceSource.GetTypeInfo();
string resourcePrefix = GetResourcePrefix(typeInfo);
Assembly assembly = typeInfo.Assembly;
value = CreateResourceManagerStringLocalizer(assembly, resourcePrefix);
_localizerCache[resourceSource.AssemblyQualifiedName] = value;
}

return value;
}
```
You can see that the cache key is Type AssemblyQualifiedName, however, in ALC, after hot overloading, AssemblyQualifiedName may still be consistent.
The Type handle, Type resource, and so on have changed after hot overloading, which makes it impossible for me to obtain resource information after hot overloading

### Expected Behavior

I hope to change it to a virtual method, which can be customized by users

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

8.0.202

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at ResourceManagerStringLocalizerFactory.Create(Type resourceSource) and inspect how _localizerCache uses AssemblyQualifiedName when types are loaded in an ALC. Reproduce the .NET 8.0.202 hot-overloading scenario if possible; done means the factory supports the requested user customization and resource lookup remains usable after the type changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
localization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.