I'm currently working on a Blazor WebAssembly Asp.NET hosted in .NET Standard 2.1.
I try to load resources files from a separate .NET Standard 2.1. C# Class library.
Unfortunately I always get the following error:
"Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Could not load type of field 'MyNamespace.Footer:k__BackingField' (0) due to: Could not load file or assembly 'MyNamespace.Resources, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies."
- My .resx files are set to Access Modifier: Public and look like this in the properties tab:
My project structure looks like this:
- MyNamespace.BlazorApp.Client
- MyNamespace.BlazorApp.Server
- MyNamespace.BlazorApp.Resources
I load the resources like this:
- MyNamespace.BlazorApp.Client:
In my Program.cs Main Method I set the current culture like this:
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
and I add the Localization service:
services.AddLocalization();
Further on in a .razor page where I want to use the culture setting I inject the Localization service:
@inject IStringLocalizer<Translations> Translations
- MyNamespace.BlazorApp.Server
Here I simply load the project reference to my resources project. I don't use the .resx in this project.
Do you know how to load resources from an external .NET Standard 2.1. C# Class library into a Blazor Wasm project?
AddRazorSupportForMvc
in the project file? ref: docs.microsoft.com/en-us/aspnet/core/migration/… – mynkow