Jamie Brown
Jamie Brown
CC#
Created by mixels on 9/18/2024 in #help
Accessing configuration inside CreateDefaultBuilder chain
Weird, I'm pretty sure there's some dark desrialisation magic that should be possible, however being dark desrialsation magic it's not something I fully understand 😅
8 replies
CC#
Created by mixels on 9/18/2024 in #help
Accessing configuration inside CreateDefaultBuilder chain
{[WebService:BindUrls:0, http://0.0.0.0:8180]}
Is that varbatim the json? Looks like it's wrapped in an array?
8 replies
CC#
Created by mixels on 9/18/2024 in #help
Accessing configuration inside CreateDefaultBuilder chain
No problem, I've also been learning it recently and had a similar issue yesterday haha!
8 replies
CC#
Created by Jamie Brown on 9/17/2024 in #help
✅ Can't infer type arguments from usage
!close
10 replies
CC#
Created by mixels on 9/18/2024 in #help
Accessing configuration inside CreateDefaultBuilder chain
In
configRoot.GetSection("WebService").GetValue<string[]>("BindUrls");
configRoot.GetSection("WebService").GetValue<string[]>("BindUrls");
you're trying to get a string[], but in your appsettings.json you just have it as a string value. either you need to change what you're requesting to a string, or if you're expecting multiple values, you need to reflect it as an array in json. i.e.
{
"WebService": {
"BindUrls": [
"http://0.0.0.0:8180"
]
}
}
{
"WebService": {
"BindUrls": [
"http://0.0.0.0:8180"
]
}
}
8 replies
CC#
Created by Jamie Brown on 9/17/2024 in #help
✅ Can't infer type arguments from usage
Actually this is one of the (all too common unfortunately) cases where I've made the problem more complex than it needs to be, you can just do:
public static IEnumerable<TItem> Flatten<TItem>(this IEnumerable<IEnumerable<TItem>> items)
{
return items.SelectMany(item => item);
}
public static IEnumerable<TItem> Flatten<TItem>(this IEnumerable<IEnumerable<TItem>> items)
{
return items.SelectMany(item => item);
}
And it will work without issue. I had it in my mind that the compiler would struggle to infer the type of the inner collection, but just goes to show I need to have a little more faith!
10 replies