Working on a C# .NET application for Windows Desktop which does 3D rendering. On laptops with dual video card configs (integrated Intel video and NVidia for example), the problem can arise that the user has not changed the NVidia control panel setting to prefer the NVidia card. As a result the app may pick the integrated video and perform poorly.
Were this unmanaged code, one could do the below to export an integer from the main exe and apparently the NVidia software will detect this and then force the app to run with the NVidia card without the user having to change the control panel setting (requiring them to do this isn't realistic and it results in a bad first impression of application performance).
extern "C" {
_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
}
In order to do the above with a .NET C# executable (it has to be the main exe not a DLL apparently), I'm attempting to use the approach outlined at the below link.
http://lucasmagder.com/blog/2014/05/exporting-data-symbols-in-c-for-nvidia-optimus/
The approach there is to, in post-build, dissassemble the .exe, then modify the IL, inserting the below at the start of a dummy method and then re-assemble the modified IL creating a new exe.
.export [0] as NvOptimusEnablement
Then at runtime there's some more stuff it does to get the value set. But, the issue is that when we try and run we get the following error from assembly loading.
Could not load file or assembly '...' or one of its dependencies. Attempt to load an unverified executable with fixups (IAT with more than 2 sections or a TLS section.) (Exception from HRESULT: 0x80131019
Searching on this error suggests that this is caused by a managed assembly which also contains unmanaged code, which is of course exactly what we're trying to do (Exception with Resolving assemblies: Attempt to load an unverifiable executable with fixups).
Anyone else have experience with this? I'm guessing back when that workaround was created this all worked, but maybe the assembly loading is more strict now? Anyonw know of a workaround?
User contributions licensed under CC BY-SA 3.0