Destination Unknown
Destination Unknown
CC#
Created by Destination Unknown on 1/16/2025 in #help
Read file from wwwroot in Blazor web app
I have a JSON file in wwwroot/Resources/form-input-list.json In my razor file I wanna do this:
@code {
private Field[]? fields;

protected override async Task OnInitializedAsync()
{
var json = await Http.GetFromJsonAsync<FormData>("Resources/form-input-list.json");
fields = json?.fields;
}

private class FormData
{
public Metadata metadata { get; set; }
public Field[] fields { get; set; }
}

private class Metadata
{
public int version { get; set; }
public string project { get; set; }
}

private class Field
{
public string type { get; set; }
public string id { get; set; }
public string name { get; set; }
public string labelText { get; set; }
public string helperText { get; set; }
public bool isRequired { get; set; }
public Item[] items { get; set; }
public string placeholderText { get; set; }
}

private class Item
{
public string id { get; set; }
public object value { get; set; }
public string labelText { get; set; }
}
}
@code {
private Field[]? fields;

protected override async Task OnInitializedAsync()
{
var json = await Http.GetFromJsonAsync<FormData>("Resources/form-input-list.json");
fields = json?.fields;
}

private class FormData
{
public Metadata metadata { get; set; }
public Field[] fields { get; set; }
}

private class Metadata
{
public int version { get; set; }
public string project { get; set; }
}

private class Field
{
public string type { get; set; }
public string id { get; set; }
public string name { get; set; }
public string labelText { get; set; }
public string helperText { get; set; }
public bool isRequired { get; set; }
public Item[] items { get; set; }
public string placeholderText { get; set; }
}

private class Item
{
public string id { get; set; }
public object value { get; set; }
public string labelText { get; set; }
}
}
And in my program.cs I have defined it like so:
using nhs_frontend_csharp.frontend.Components;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();

builder.Services.AddHttpClient();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:8081/") });

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
}

app.UseStaticFiles();
app.UseAntiforgery();

app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();

app.Run();
using nhs_frontend_csharp.frontend.Components;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();

builder.Services.AddHttpClient();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:8081/") });

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
}

app.UseStaticFiles();
app.UseAntiforgery();

app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();

app.Run();
Yet I keep receiving HTTP Exceptions.
5 replies
CC#
Created by Destination Unknown on 1/16/2025 in #help
Visual Studio integration with Docker Compose not functioning as expected.
Hello, I have on solution level a docker-compose file which I use to containerize my application. In Visual Studio I have because of this also a start button with Docker Compose. Yesterday I decided to make some changes in my Docker-compose file. Yet because of this I am unable to launch my project again.
The active launch profile Docker Compose is not valid. The services 'blob-storage' used in launch profile are not present in the docker compose files.
The active launch profile Docker Compose is not valid. The services 'blob-storage' used in launch profile are not present in the docker compose files.
When I click on this error message, Visual Studio redirects me to this file: Microsoft.VisualStudio.Docker.Compose.targets. I have tried to clean and rebuild the project but I have no clue on how to resolve this issue. Deleting this file is discouraged either.
23 replies