Open LunaWanderer1 opened 9 months ago
Hi @eliyammine could you please let me the steps to reproduce?
Can you reproduce it on the repo sample?
https://github.com/eliyammine/LocalizationDotNet8/commits/master/
I started with the template by Microsoft and my last commit is all the changes I did to reproduce.
You can see when you run it that it never switches to WASM because it crashes trying to find the path.
The issue seems to be stemming from Assembly.GetExecutingAssembly().Location being null for PathHelpers.GetApplicationRoot()
Could some sort of workaround being that it can accept a URL where it downloads it from?
I've tried the following, downloading the file before initializing it but having no luck with that either (it does download the file but the issue above still occurs):
builder.Services.AddJsonLocalization(async options =>
{
using (ServiceProvider serviceProvider = builder.Services.BuildServiceProvider())
{
var httpClient = serviceProvider.GetRequiredService<HttpClient>();
var response = await httpClient.GetAsync("Resources/fr-FR.json");
Directory.CreateDirectory("Resources");
if (response.IsSuccessStatusCode)
{
string json = await response.Content.ReadAsStringAsync();
File.WriteAllText("Resources/fr-FR.json", json);
}
}
options.ResourcesPath = "Resources";
})
Could you please help to reproduce the issue by modifying the repo sample, so I can debug easily? Feel free to create a PR or fork the repo then create a branch with the required changes
Would you like me to create a new sample? The one difference that would be hard to test in any of the samples would be the AutoInteractivity mode since both Blazor projects are standalone and not connected as a Hosted Blazor WebAssembly App
I need a sample that uses the library then I can add it to the code base locally after that I can test the issue
Created under: https://github.com/hishamco/My.Extensions.Localization.Json/pull/80
Do note that once the page loads, you need to refresh once for the wasm to kick in and then you get the error
I can reproduce the issue, working on it ...
Hey @hishamco I worked out the logic by debugging with the library and I was able to get it working by using embedded resources and allowing it to load that embedded resource if the file does not exist (both needed for Server/Wasm).
I hope this helps find a proper solution, the commit is in #80
I am currently using .NET 8 with Interactive Auto for Blazor and having trouble getting the WASM part working. I was able to get the Server Part working with:
builder.Services.AddJsonLocalization(options => options.ResourcesPath = "wwwroot/Resources");
But that doesn't seem to work on the Wasm part.
The console error I get is:
One or more errors occurred. (Value cannot be null. (Parameter 'path1'))
I am using a general file: "fr-FR.json" similar to one of the samples in the repo.
Let me know if you have an idea on how to get it working.