Closed edgarssults closed 2 years ago
Reloading RESX files at runtime is not supported, as you already mentioned they are compliled files, and so the app must be restarted in order to re-generate the compiled RESX files.
But at least you don't need to deploy the app again, it will generate compiled resx resources once the app is restarted.
Ah, so an app restart should load the RESX changes? This would still be good, but it's not working for me.
I have the files set as Content and CopyToOutput, they end up in the Resources folder on publish. But if I make any changes to them they are ignored. Otherwise the translation works fine. So it feels like the resources are not recompiled when the app starts? Or the files themselves are not used during startup?
From project file:
<PublishSingleFile>false</PublishSingleFile>
<SelfContained>false</SelfContained>
<PublishReadyToRun>false</PublishReadyToRun>
Am I missing some kind of configuration or misunderstood how it works? I am hosting in IIS, but the behavior is the same when starting the published app executable.
so an app restart should load the RESX changes?
Yes, it will generate the compiled files with changes applied.
See Best practices and recommendations page, especially step no.9 to export resources to resx.
I now understand it's supposed to load the changes to the RESX files, bit it's just not happening for me. The results are not affected, I can even delete the published RESX files and translation still works.
Your ResxLocalizationSample doesn't reload them either, the resources are embedded into the binaries during publish. If I change the resources to be Content and to be copied, making changes to them doesn't affect anything.
Maybe there's a misunderstanding about what I'm trying to achieve?
The translation service do not update resx files, if you need to update the resources choose XML or DB approach, then export to resx.
The translation service works with all resources but it only updates XML and DB. If the translation service is used with resx it will show the translation but will not edit the resx, so the translation will be lost after restarting the app.
I can help more if you share your startup file.
No, I don't expect the RESX file to be updated by the app. I expected changes in the RESX file to be reflected in the app when it is restarted without rebuilding, which is not happening.
To be clear, these are the steps:
I decided to write my own implementation of IStringLocalizer which reads the RESX files as XML on startup and caches the strings in a dictionary.
Does the library support reloading RESX file contents at runtime? As I understand ASP.NET Core does not support this since the resource files are compiled. I can have the resource files copied to the output folder, but changing them does not have any effect.
I know it's not the best use case, but this is what an ASP.NET MVC 5 app that I'm migrating to ASP.NET 6 does - customers have the ability to change the texts by changing the RESX files in App_GlobalResources.
Found the library here: https://stackoverflow.com/questions/66336205/update-resx-files-at-runtime-in-net-core