Ploot
Ploot
CC#
Created by CyberBotX on 9/23/2024 in #help
Is it possible to use Reflection to replace a static readonly field without the static constructor?
I feel like the better approach would be to look into ways to stop the tool generating such code in the first place
31 replies
CC#
Created by MJT on 9/14/2024 in #help
✅ False Positive Virus Detection on my C# network ping code
Defender is pretty twitchy when it comes to unsigned executables. Generally the best way you can avoid this is by signing executables you publish
12 replies
CC#
Created by Ploot on 9/4/2024 in #help
✅ AddHttpClient and AddHostedService
Ah. Im my actual project I do, this was just from my project i use for testing stuff
29 replies
CC#
Created by Ploot on 9/4/2024 in #help
✅ AddHttpClient and AddHostedService
TLS as in like transport layer security?
29 replies
CC#
Created by Ploot on 9/4/2024 in #help
✅ AddHttpClient and AddHostedService
Just how I was taught to do it. I haven't used any of the hosting stuff outside this project so I have little knowledge about it's best practices
29 replies
CC#
Created by Ploot on 9/4/2024 in #help
✅ AddHttpClient and AddHostedService
That code is functionally the same as what I'm running and exhibits the same behaviour. The incorrect HttpClient is injected when using the commented out line but works fine with the GetRequiredService method. Idk if I'm expecting something that's incorrect from the DI or if this is weird behaviour :akarishrug:
29 replies
CC#
Created by Ploot on 9/4/2024 in #help
✅ AddHttpClient and AddHostedService
Sorry, ended up a little busy. This is my min repro code
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Playground;

public static class Program
{
public static async Task Main()
{
IHostBuilder hb = Host.CreateDefaultBuilder();

hb.ConfigureServices((_, serviceCollection) =>
{
//serviceCollection.AddHostedService<TestService>();
serviceCollection.AddHostedService(x => x.GetRequiredService<TestService>());
serviceCollection.AddHttpClient<TestService>(x => x.Timeout = TimeSpan.FromSeconds(30));
});

await hb.Build().StartAsync();
await Task.Delay(-1);
}
}

public class TestService(HttpClient httpClient) : IHostedService
{
public Task StartAsync(CancellationToken cancellationToken)
{
Console.WriteLine(httpClient.Timeout);
return Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken)
=> throw new NotImplementedException();
}
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Playground;

public static class Program
{
public static async Task Main()
{
IHostBuilder hb = Host.CreateDefaultBuilder();

hb.ConfigureServices((_, serviceCollection) =>
{
//serviceCollection.AddHostedService<TestService>();
serviceCollection.AddHostedService(x => x.GetRequiredService<TestService>());
serviceCollection.AddHttpClient<TestService>(x => x.Timeout = TimeSpan.FromSeconds(30));
});

await hb.Build().StartAsync();
await Task.Delay(-1);
}
}

public class TestService(HttpClient httpClient) : IHostedService
{
public Task StartAsync(CancellationToken cancellationToken)
{
Console.WriteLine(httpClient.Timeout);
return Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken)
=> throw new NotImplementedException();
}
29 replies
CC#
Created by Ploot on 9/4/2024 in #help
✅ AddHttpClient and AddHostedService
This does ^^. Seems a little bit of strange design but hey, it's better than what I had!
29 replies
CC#
Created by Ploot on 9/1/2024 in #help
✅ Per request timeout
That's a very strange design choice but thank you
6 replies
CC#
Created by Ploot on 8/30/2024 in #help
Grainy gif output when using `Graphics` on source Bitmap
I hadn't actually thought to check the metadata, unfortunately MediaInfo is showing both the input and output to be identical from a metadata standpoint. Whatever is happening seems to be caused by the use of Graphics messing with the bitmap somehow as not calling any graphics g.DrawX methods results in a 1:1 recreation of the input. I did also try a lower smoothing mode but it was resulting in some pretty jagged lines, although that may be because my DrawStringOutlined extension method is using a GraphicsPath to draw the text and it's outline? I haven't tested much tbh and this is my first time using System.Drawing stuff
3 replies
CC#
Created by O.S on 8/28/2024 in #help
New in the game
I second this ^ Different people learn in different ways so this advise won't be universal but for me personally I've always learnt the most when worked on something I've been passionate about and that has been somewhat outside my current knowledge but not crazy ambitious. also, in case it needs saying, never be ashamed you have to look something up or ask others for help
14 replies
CC#
Created by Ploot on 8/27/2024 in #help
✅ JsonSerializer ignoring encoding options?
Thank you :AA_Vanilla_Pray:
4 replies
CC#
Created by Ploot on 8/7/2024 in #help
Don't start hosted services on start
I could just check the state of the client in each service and wait for it to be logged in before proceeding but that itself feels like a hack than a proper solution. Any ideas on a better way to go about this?
15 replies
CC#
Created by Ploot on 8/7/2024 in #help
Don't start hosted services on start
Reflecting, it may very well be an architectural problem. Currently I don't know of a better way of handling this. This problem arises because I am using this for a discord bot. The bot client itself is registered as a singleton with the DI collection and a hosted startup service performs configuration for this client and logs it in. My other hosted services are then using this discord client to perform various tasks independently (Think timers, checking channels for new messages, ect). My issue is coming from the other services attempting to use the client before it has chance to log in.
15 replies
CC#
Created by R ㄨ on 6/28/2024 in #help
✅ I have an encrypted file and I suspect it is a malicious virus. Can I decrypt it?
No description
6 replies
CC#
Created by Ploot on 3/21/2024 in #help
✅ [Solved] [Polly] Not all code paths return a value
its 5am
5 replies
CC#
Created by Ploot on 3/21/2024 in #help
✅ [Solved] [Polly] Not all code paths return a value
:AA_Kanna_Facepalm:
5 replies