Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor Web App .NET 8, Server and Wasm #79

Open
LunaWanderer1 opened this issue Jan 3, 2024 · 10 comments
Open

Blazor Web App .NET 8, Server and Wasm #79

LunaWanderer1 opened this issue Jan 3, 2024 · 10 comments
Labels

Comments

@LunaWanderer1
Copy link

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.

@hishamco
Copy link
Owner

hishamco commented Jan 3, 2024

Hi @eliyammine could you please let me the steps to reproduce?

@hishamco
Copy link
Owner

hishamco commented Jan 3, 2024

Can you reproduce it on the repo sample?

@LunaWanderer1
Copy link
Author

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.

@LunaWanderer1
Copy link
Author

LunaWanderer1 commented Jan 3, 2024

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";
})

@hishamco
Copy link
Owner

hishamco commented Jan 3, 2024

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

@LunaWanderer1
Copy link
Author

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

@hishamco
Copy link
Owner

hishamco commented Jan 3, 2024

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

@LunaWanderer1
Copy link
Author

Created under: #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

@hishamco
Copy link
Owner

hishamco commented Jan 4, 2024

I can reproduce the issue, working on it ...

@hishamco hishamco added the bug label Jan 4, 2024
@LunaWanderer1
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants