Bored Student
Bored Student
Explore posts from servers
CC#
Created by Bored Student on 5/22/2024 in #help
How to Dockerize
I have the following docker file
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /app

# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 5000
ENTRYPOINT ["dotnet","ControllerApi.dll"]
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /app

# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build-env /app/out .
EXPOSE 5000
ENTRYPOINT ["dotnet","ControllerApi.dll"]
pretty much copy paste from Microsoft https://learn.microsoft.com/de-de/dotnet/core/docker/build-container?tabs=linux&pivots=dotnet-8-0 but i encounter an error i dont have in any other environment about not finding serilog
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Serilog.Sinks.File, Version=5.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10'. The system cannot find the file specified.
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Serilog.Sinks.File, Version=5.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10'. The system cannot find the file specified.
I looked that my .csproj only reference serilog nuget package not the dll directly, and i'm not even using the file sink
3 replies
CC#
Created by Bored Student on 5/8/2024 in #help
API Endpoint is Invoked with `null` Argument
I am sending the following call
const requestOptionsUpdateAddress = {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Authorization": "Bearer " + token,
},
body: JSON.stringify({
"lable" : nameInput.value,
"poBox" : typeDropdown.value,
"poNumber" : packstationVal,
"town": cityInput.value,
"zipCode": zipInput.value,
"road": streetNameInput.value,
"houseNumber" : streetNumberInput.value,
"country": countryInput.value,
})
}
const responseUpdateAddress = await fetch(baseUri.concat("/user/updateAddress"), requestOptionsUpdateAddress);
const requestOptionsUpdateAddress = {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Authorization": "Bearer " + token,
},
body: JSON.stringify({
"lable" : nameInput.value,
"poBox" : typeDropdown.value,
"poNumber" : packstationVal,
"town": cityInput.value,
"zipCode": zipInput.value,
"road": streetNameInput.value,
"houseNumber" : streetNumberInput.value,
"country": countryInput.value,
})
}
const responseUpdateAddress = await fetch(baseUri.concat("/user/updateAddress"), requestOptionsUpdateAddress);
to the Following API endpoint
c#
[HttpPost("/user/updateAddress")]
[Authorize]
public async Task<IResult> UpdateSingleAddress([FromBody] UpdateAddress ad)
{
if (ad == null)
{
var buffer = new byte[HttpContext.Request.ContentLength ?? 0];
var read = await HttpContext.Request.Body.ReadAsync(buffer);
var body = Encoding.UTF8.GetString(buffer);
_logger.LogWarning("No data provided : {0}", body);
return Results.Problem("No data provided", statusCode: 400, title: "No data provided");
}
...
}
c#
[HttpPost("/user/updateAddress")]
[Authorize]
public async Task<IResult> UpdateSingleAddress([FromBody] UpdateAddress ad)
{
if (ad == null)
{
var buffer = new byte[HttpContext.Request.ContentLength ?? 0];
var read = await HttpContext.Request.Body.ReadAsync(buffer);
var body = Encoding.UTF8.GetString(buffer);
_logger.LogWarning("No data provided : {0}", body);
return Results.Problem("No data provided", statusCode: 400, title: "No data provided");
}
...
}
Yet ad is null and this if triggers. First Question : why doesn't the Middleware already stop an Empty request ? Second Question : I confirmed with the Browser DevTools that the request isn't actually empty, so where does my data go ? DTO Class for reference
c#
public class UpdateAddress
{
public string Lable { get; set; }
public bool POBox { get; set; }
public int? PONumber { get; set; }

public string Town { get; set; }
public int ZipCode { get; set; }
public string Road { get; set; }
public string HouseNumber { get; set; }
public string Country { get; set; }
}
c#
public class UpdateAddress
{
public string Lable { get; set; }
public bool POBox { get; set; }
public int? PONumber { get; set; }

public string Town { get; set; }
public int ZipCode { get; set; }
public string Road { get; set; }
public string HouseNumber { get; set; }
public string Country { get; set; }
}
13 replies
CC#
Created by Bored Student on 1/26/2024 in #help
Neat String interpolation
C#
foreach(file in files){
//Process file
Console.WriteLine($"Processed File [{file.Nr}/{files.Count}]");
}
C#
foreach(file in files){
//Process file
Console.WriteLine($"Processed File [{file.Nr}/{files.Count}]");
}
I have this little something, and I want the counter to stay fixed width so [ 1/50] instead of [1/50] how can I do this ? As simple as possible, I just want it to look neat not write a TUI framework. I found $"{val , fixedWidth}" but that only works with constants so it can't adapt if I reach 100 files.
16 replies
CC#
Created by Bored Student on 1/18/2024 in #help
Type Inference strategies?
I'm generating Class Definition from XML. And currently I just save the Value strings. But I want stricter validation abilities, so I want to find suitable base types, e.g. detect number types. Do you have any ideas how to go about that efficiently and how to balance strictness vs. information loss in small types ?
1 replies
CC#
Created by Bored Student on 1/15/2024 in #help
Propagate Changes to WPF
I'm using WPF with Unity Container and Prism. I've got a save button which is supposed to activate once I have data. I log MyCommand.CanExecute() which is true but it remains disabled in the GUI. MyCommand.RaiseCanExecuteChange() does not exist in Prism. (Or at least can't be resolved)
2 replies