Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How do I get text from IStringLocalizer from file on Blazor? [closed]

$
0
0

I'm trying to use Istringlocalizer from C# on an MudBlazor html solution. I've got all Istringlocalizer configuration and it is working all correctly but I can't get the text from a file.

To put it on an example, I've got file.txt, also in the same folder for example file.txt.en-US on my wwwroot folder. A file resources.resx and resources.resx.en-US where I put a new entrance with the key textFromFile.

All right until now but when I put the IStringLocalizer<...> txt["textFromFile"] which is on every page I use initialized through @inject IStringLocalizer<...> txt on the page doesn't work. Why? I know that it isn't just a string but a byte[] but the variable doesn't allow me to type int in another way such as (byte[])txt["textFromFile"]. Is it posible that I'm understanting wrong how it works and the referenced file must have a specified format such as json?

This resource files resources.resx got its resources.Designer.cs on which has an entrance for each key. Normal entrances look like:

internal static string Key_Example{     get {        return ResourceManager.GetString("Key_Example",resourceCulture);    }}

and the one I want from a file looks like:

internal static byte[] Key_Example{    get {        object obj = ResourceManager.GetObject("Key_Example", resourceCulture);        return ((byte[])(obj));    }}

I tried to change it so it returns only a string but still the same error:

internal static string Key_Example{    get {        byte[] obj = (byte[])ResourceManager.GetObject("Key_Example", resourceCulture);        string result = "";        foreach (byte obj2 in obj)        {            result += obj2.ToString();        }        return result;    }}

On html, on a blazor page:

...@inject IStringLocalizer<Locals.FrontPage> front...<h3>@front["Key"]<h3><p>@front["Key_File"]<p>

Error log:

warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]      Unhandled exception rendering component: Cannot access a disposed object.      System.ObjectDisposedException: Cannot access a disposed object.         at fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]      Unhandled exception in circuit '6qYQC988G4gwi7cf1MN8Bz6hsfckOq8CghWZccVVZN4'.      System.ObjectDisposedException: Cannot access a disposed object.warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]          Unhandled exception rendering component: Resource was of type 'ByteArray' instead of String - call GetObject instead.    fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]          Unhandled exception in circuit '6qYQC988G4gwi7cf1MN8Bz6hsfckOq8CghWZccVVZN4'.          System.InvalidOperationException: Resource was of type 'ByteArray' instead of String - call GetObject instead.

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>