blazor-server-sideresx

C# Blazor shared resource files error: The resource type GlobalResources does not have an accessible static property named


I have a net6 project (V2.resources) where I've put my resource files in.

I have a Blazor server project in which I use the resources for localization. This works fine. I also have a net6 Models project (V2.Models). This contains all my viewmodels where some of them have DataAnnotions to validate.

[Required(ErrorMessageResourceName = "RequiredField", ErrorMessageResourceType = typeof(GlobalResources))]
        public string Name { get; set; }

The problem occures here. When the name field is invalid it throws the following error:

The resource type 'V2.Resources.GlobalResources' does not have an accessible static property named 'RequiredField'

anyone has an idea where does this comes from? They are accessible from the Blazor project. The resource file is set to PublicResXFileCodeGenerator.

Project structure:

enter image description here

In Blazor project Program.cs

builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");

Solution

  • Found it :)

    The models project was missning nuget package:

    Microsoft.Extensions.Localization

    Now it works as a charm.