© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
40 replies
Esa

Need help debugging a tiny console app on server

Halp. I'm losing my mind rapidly.

Scenario: I'm writing a tcp client tester to PoC something, and I've written it as a tiny console application where I use dependency injection to see that that aspect also works.

services.AddOptions<SysConfig>()
    .Configure<IConfiguration>((options, configuration) => configuration.Bind(SysConfig.SectionName, options))
    .Validate(options => options.Port is not default(int), $"{nameof(SysConfig.Port)} is not defined!")
services.AddOptions<SysConfig>()
    .Configure<IConfiguration>((options, configuration) => configuration.Bind(SysConfig.SectionName, options))
    .Validate(options => options.Port is not default(int), $"{nameof(SysConfig.Port)} is not defined!")


This is how I normally do it.
However... When I run this exe on the target server, it fails on the Validation step. It says the values are default. And this is where it gets weird. If I replace that neat configuration oneliner with an explicit behemoth that manually gets the required section, retrieves the string and binds it to the property - then it works:
.Configure<IConfiguration>((options, configuration) =>
{
    IConfigurationSection sysSection = configuration.GetRequiredSection("Sys");
    if (!sysSection.Exists()) throw new Exception("Missing section \"Sys\" in configuration!");

    var portAsString = sysSection.GetValue<string>("Port");

    options.Port = int.Parse(portAsString!);
})
.Configure<IConfiguration>((options, configuration) =>
{
    IConfigurationSection sysSection = configuration.GetRequiredSection("Sys");
    if (!sysSection.Exists()) throw new Exception("Missing section \"Sys\" in configuration!");

    var portAsString = sysSection.GetValue<string>("Port");

    options.Port = int.Parse(portAsString!);
})


But attempting to oneline it causes the error where everything is default, and thus failing validation.

This only happens on the target server which has a .net 8.0 x64 runtime installed, whereas I have a .net 8.0 x64 SDK installed on my dev environment.

Does this make sense to anyone? I don't really know where to start looking, apart from installing an SDK on the server to see - but that sounds very wrong lol.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Need pointers on code for console app.
C#CC# / help
16mo ago
✅ Need help with debugging C++
C#CC# / help
2y ago
need help with a console menu
C#CC# / help
2y ago
Need Help Debugging .NET Frontend Integration
C#CC# / help
7mo ago