Stay
Stay
CC#
Created by Stay on 12/29/2022 in #help
✅ Prevent carriage return from being added in the new multi-line string literal?
How to prevent \r from being added in a multi-line string literal?
"""
First Line
Second Line
"""
"""
First Line
Second Line
"""
C# is adding a \r after the \n only in Windows. I know that Windows uses \n\r to indicate new lines, but can i somehow disable that?
14 replies
CC#
Created by Stay on 12/1/2022 in #help
❔ System.InvalidCastException when connecting to MariaDB in docker
Hello! I have a console application that works fine in Windows and WSL2. For some reason, when running it under docker (linux) with the dotnet-runtime 6.0 image i get an exception when pinging the database
System.InvalidCastException: Object cannot be cast from DBNull to other types.
at System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider)
at MySql.Data.MySqlClient.Driver.LoadCharacterSets(MySqlConnection connection)
at MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection)
at MySql.Data.MySqlClient.MySqlConnection.Open()
at MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>b__75_0()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
System.InvalidCastException: Object cannot be cast from DBNull to other types.
at System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider)
at MySql.Data.MySqlClient.Driver.LoadCharacterSets(MySqlConnection connection)
at MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection)
at MySql.Data.MySqlClient.MySqlConnection.Open()
at MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>b__75_0()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
This exception happen when i OpenAsync the connection, not while reading anything. I can login into the database from inside that container just fine with the mariadb-client What might be causing this?
2 replies
CC#
Created by Stay on 11/9/2022 in #help
❔ Reducing networking syscalls
4 replies
CC#
Created by Stay on 11/5/2022 in #help
Application works on Windows and WSL2 but fails in docker (Linux). Broken pipe
I have an application that establishes a TCP connection to another Java application. For some reason, when i run both applications in the same docker container (LInux, using the Dev Containers extension of vscode) the dotnet app reads giberish or gets disconnected by the java app because of a "broken pipe" exception. This does not happen in Windows 10 or WSL2 (Ubuntu). I understand that without looking at the code this is not a very helpful description, but i can't debug as good as in Rider in vscode and i don't understand why it would fail under a docker container and not on WSL2.
1 replies
CC#
Created by Stay on 10/15/2022 in #help
[ASP.NET Core] Apply a selfsigned certificate to asp.net core?
So i don't know exactly what i'm doing, but i'm trying to do the following: Let's say that i have the following domain purchased: mywebsite.com. I'm trying to redirect api.mywebsite.com to localhost by adding in the hosts file
api.mywebsite.com 127.0.0.1
api.mywebsite.com 127.0.0.1
As expected this does not play nice with browsers or other programs, because the certificate provided by ASP.NET Core has nothing to do with mywebsite.com or api.mywebsite.com. I tried creating a self signed certificate like this in Powershell
New-SelfSignedCertificate -DnsName "api.mywebsite.com" -CertStoreLocation cert:\LocalMachine\My -FriendlyName "Dev cert for api.mywebsite.com" -NotAfter (Get-Date).AddYears(15)
New-SelfSignedCertificate -DnsName "api.mywebsite.com" -CertStoreLocation cert:\LocalMachine\My -FriendlyName "Dev cert for api.mywebsite.com" -NotAfter (Get-Date).AddYears(15)
But i don't know how to use that in ASP.NET Core (if that's even what i have to do to make this work) So is this possible or using a domain like that in localhost is completly impossible (without warnings atleast)
2 replies
CC#
Created by Stay on 10/10/2022 in #help
EF Core not fetching sub-entities by Id [Answered]
I'm kinda new to EF Core so maybe the terminology is not right. I have the following models: Player:
public sealed class Player
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string Id { get; set; } = null!;
public string Username { get; set; } = null!;
public Group Group { get; set; } = null!;
}
public sealed class Player
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string Id { get; set; } = null!;
public string Username { get; set; } = null!;
public Group Group { get; set; } = null!;
}
Group:
public sealed class Group
{
public string Id { get; set; } = null!;
public string? ParentId { get; set; }
public string Name { get; set; } = null!;
public string[] Permissions { get; set; } = Array.Empty<string>();
}
public sealed class Group
{
public string Id { get; set; } = null!;
public string? ParentId { get; set; }
public string Name { get; set; } = null!;
public string[] Permissions { get; set; } = Array.Empty<string>();
}
And tables: Players:
CREATE TABLE IF NOT EXISTS public.players
(
"Id" character varying(36) COLLATE pg_catalog."default" NOT NULL,
"Username" character varying(64) COLLATE pg_catalog."default",
"GroupId" character varying(36) COLLATE pg_catalog."default",
CONSTRAINT players_pkey PRIMARY KEY ("Id")
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.players
OWNER to postgres;
CREATE TABLE IF NOT EXISTS public.players
(
"Id" character varying(36) COLLATE pg_catalog."default" NOT NULL,
"Username" character varying(64) COLLATE pg_catalog."default",
"GroupId" character varying(36) COLLATE pg_catalog."default",
CONSTRAINT players_pkey PRIMARY KEY ("Id")
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.players
OWNER to postgres;
Groups:
CREATE TABLE IF NOT EXISTS public.groups
(
"Id" character varying(36) COLLATE pg_catalog."default" NOT NULL,
"ParentId" character varying(36) COLLATE pg_catalog."default",
"Name" character varying(64) COLLATE pg_catalog."default",
"Permissions" character varying(64)[] COLLATE pg_catalog."default",
CONSTRAINT groups_pkey PRIMARY KEY ("Id")
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.groups
OWNER to postgres;
CREATE TABLE IF NOT EXISTS public.groups
(
"Id" character varying(36) COLLATE pg_catalog."default" NOT NULL,
"ParentId" character varying(36) COLLATE pg_catalog."default",
"Name" character varying(64) COLLATE pg_catalog."default",
"Permissions" character varying(64)[] COLLATE pg_catalog."default",
CONSTRAINT groups_pkey PRIMARY KEY ("Id")
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.groups
OWNER to postgres;
It works fine when adding a player, it inserts the GroupId as i would expect it to, but when fetching
var player = await _context.Players.FirstOrDefaultAsync(x => x.Id == request.Id);
var player = await _context.Players.FirstOrDefaultAsync(x => x.Id == request.Id);
Group is null Why is this happening?
3 replies
CC#
Created by Stay on 8/20/2022 in #help
Store generic Func T inside a colletion [Answered]
I have a generic Func<T>, which i wan't to store in a Dictionary, but i don't know how to do that since apparently the restriction of T is not enough
108 replies