Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Some Windows users are seeing this on launch:
Causes
In #3107, we started trying to initialize CurlSharp at startup to avoid thread-unsafe initialization, because the warning message about it was chronically spamming the Discord notifications channel for the NetKAN bot. Apparently CurlSharp needs to load the Visual C++ runtime to do its work, but some users have multiple copies of it in their
PATH
, which confuses Windows if it's a 32-bit copy:(The misleading error message blaming the application for this is just one of dozens of ways Windows could do better here.)
Any call to
Curl.Init()
was supposed to catch and ignore all exceptions, but this wasn't done with the new calls in #3107 (because I didn't know about this requirement/assumption, because that's life with code that relies on exceptions for important behavior). Instead, the missing DLL exception was caught and ignored (which probably causes other problems by preventing the fallback from being skipped during downloads on Windows), and this BadImageFormatException is uncaught.Background
According to @techman83, the CurlSharp fallback was added the first time a new TLS version requirement broke everything. (The second time was #2293, with which CurlSharp was memorably unhelpful, probably because it's not for Windows.)
The fallback is no longer needed (because .NET and Mono both support the latest TLS) and is an obstacle to refactoring the network code. Any change has to consider the possibility of multiple connections being attempted for the same URL with exceptions thrown, caught, re-thrown, etc. It can be difficult even to identify where a given change should go, and to avoid breaking something.
Workaround
@Dominiquini figured out that clearing the
PATH
environment variable helps!(Details may vary, not guaranteed effective on any particular Windows system, use at your own risk.)
Changes
Now all the libcurl stuff is removed. We try to download a URL once with WebClient, and if that doesn't work, too bad.
As well, all projects now have this set for all builds:
Previously it was only set for Debug builds, which may have played a role in how these DLLs were loaded.
Fixes #3115.
Fixes #3095.