I need to save a few variables in a modifiable config file. I made a json file in wwwroot and set it to "copy if newer". Confirmed, it is copied to wwwroot and is accessible via localhost:port/config.jsonBUT, my program.cs silently fails:
builder.Services.AddScoped(sp => { var navigationManager = sp.GetRequiredService<NavigationManager>(); var baseUri = new Uri(navigationManager.BaseUri); var httpClient = new HttpClient() { BaseAddress = baseUri }; return httpClient; });builder.Services.AddScoped<Task<Configz?>>(async p => { var httpClient = p.GetRequiredService<HttpClient>(); try { var ret = await httpClient.GetFromJsonAsync<Configz>("config.json"); //execution fails after this silently. return ret; //this line or anything between these two is never hit. } catch (Exception ex) { Console.WriteLine($"Failed to deserialize config.json: {ex.Message}"); //wish I hit this line. } });My Configz class:
public class Configz{ public string apiPortHTTP { get; set; } public string apiPortHTTPS { get; set; }}My Json:
{"apiPortHTTP": "7021","apiPortHTTPS": "7020"}Any help would be appreciated, this is really frustrating.