C
C#2y ago
pyrodistic

❔ Access Resources File

Hey, sorry to bother - quick question. I created a EmailResources.resx file inside a "Resources" folder, where I have the Name-Value pair of "ConfirmationEmailSubject" - "Verify Your Email Address". On Program.cs I have:
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.AddSingleton<IStringLocalizerFactory, ResourceManagerStringLocalizerFactory>();
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.AddSingleton<IStringLocalizerFactory, ResourceManagerStringLocalizerFactory>();
On the controller I have instantiated the _localizer (private readonly IStringLocalizer<AuthController> _localizer), I have tried to do:
_localizer["EmailResources:ConfirmationEmailSubject"];
_localizer["EmailResources:ConfirmationEmailSubject"].Value;
_localizer["ConfirmationEmailSubject"];
_localizer["ConfirmationEmailSubject"].Value;
_localizer.GetString("ConfirmationEmailSubject");
_localizer.GetString("ConfirmationEmailSubject").Value;
_localizer["EmailResources.EmailResources:ConfirmationEmailSubject"];
_localizer["EmailResources.EmailResources:ConfirmationEmailSubject"].Value;
_localizer["EmailResources:ConfirmationEmailSubject"];
_localizer["EmailResources:ConfirmationEmailSubject"].Value;
_localizer["ConfirmationEmailSubject"];
_localizer["ConfirmationEmailSubject"].Value;
_localizer.GetString("ConfirmationEmailSubject");
_localizer.GetString("ConfirmationEmailSubject").Value;
_localizer["EmailResources.EmailResources:ConfirmationEmailSubject"];
_localizer["EmailResources.EmailResources:ConfirmationEmailSubject"].Value;
All of these are returning "ConfirmationEmailSubject" instead of "Verify Your Email Address". What am I doing wrong? There's a lot of things I've tried on Program.cs. Still cannot do it.
3 Replies
phaseshift
phaseshift2y ago
Did you set the build properties of the folder/resource file?
pyrodistic
pyrodisticOP2y ago
Yes, it was build as a embedded resource.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server