'Statically linked WebView2Loader produce invalid binary

We are trying to integrate WebView2 into our Win32 application, and it is working fine when it links to WebView2Loader.dll.lib to load WebView2Loader.dll.

We followed the MSDN instructions to link the library statically, and this has so far failed to work. There are no errors output during the build, and even with diagnostic setting all looks perfectly correct. However, the executable produced does not have a valid PE header.

We are building an x86 executable, and it is linking with WebView2LoaderStatic.lib from the x86 folder of the WebView2 package, as downloaded with NuGet.

The used environment is:

Visual Studio 2017, with all updates installed, Build Toolset 141, Target Platform is Windows 10, Windows SDK Version is 10.0.17763.0

Update 1: We have discovered that if "Generate Debug Info" in Linker Options is turned off, a valid binary is generated. However, this is not a good solution for us in debug mode, so any ideas that might help would be deeply appreciated. Our temporary solution is to edit the project file to conditionally set the static linkage flag only when doing release builds, and ensure those doesn't contain debug info.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source