Running SDK within a windows service throws FileIO exceptions on login

I have been updating our old windows service to use the latest SDK but upon attempting to login it fails trying to load System.Net.HTTP.Formatting the SDK error states it is looking for version 5.2.6 of the file but the NuGet package installs version 5.2.7.

If I run the exact same code but inside a GUI application it works as expected. From my testing any SDK version greater than 20.3.0 will throw errors when run from console but fine from a GUI application.

Many thanks,

Danny

Please try in the Visual Studio project, Application properties to set the “Auto-generate binding redirects”, this should solve the issue.

If it does not work you will have to make a binding redirect - https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/bindingredirect-element