Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] BadImageFormatException when using the library in a .NET 4.7 project, compiled on a 64bit PC with AnyCPU and executed on 32bit PC. #151

Closed
1 task done
romerod opened this issue Sep 26, 2024 · 3 comments · Fixed by #154 or #168
Labels
bug Something isn't working

Comments

@romerod
Copy link

romerod commented Sep 26, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When the library is used in a project compiled with AnyCPU which is compiled on a x64 bit system the applications fails with a BadImageFormatException on 32bit PC as the Yubico.NativeShims.dll in the build output folder is the x64 version. The same thing happens when setting the Prefer32Bit flag.

The Yubico.NativeShims.targets file in the Yubico.NativeShims nuget package copies the file over depending of the architecture of the build system.

Expected Behavior

When a project is build with AnyCPU the build output should contain the x86 and the x64 bit of the dll.

And the dll to load should be detected on runtime. For example by using the LoadLibrary method of kernel32.dll. For the moment we worked around the issue with copying both dlls to the build output and then with a code similar to this:

if(Environment.Is64BitProcess)   
    NativeMethods.LoadLibrary("x64\Yubico.NativeShims.dll")
else
   NativeMethods.LoadLibrary("x86\Yubico.NativeShims.dll")

before calling any of the library methods.

Steps To Reproduce

  1. Create .NET 4.72 project with AnyCPU
  2. Add Yubico.YubiKey nuget package reference
  3. Call YubiKeyDevice.FindByTransport(Transport.All);
  4. Build it on a x64 PC and run it on a x32bit system

Can also be reproduced by setting the <Prefer32Bit>true</Prefer32Bit> instead of running it on 32Bit system.

Version

1.11.0

Version

5.4.3

Anything else?

No response

@romerod romerod added the bug Something isn't working label Sep 26, 2024
@romerod romerod changed the title [BUG] BadImageFormatException when using the library in a .NET 4.7 project compiled with AnyCPU on 32bit PC. [BUG] BadImageFormatException when using the library in a .NET 4.7 project, compiled on a 64bit PC with AnyCPU and executed on 32bit PC. Sep 27, 2024
@DennisDyallo DennisDyallo added the awaiting yubico action When we've got the ball label Oct 21, 2024
@DennisDyallo DennisDyallo removed the awaiting yubico action When we've got the ball label Oct 24, 2024
@DennisDyallo
Copy link
Collaborator

Thanks for the report. The fix will be added to the next release @romerod

@romerod
Copy link
Author

romerod commented Oct 24, 2024

Thank you, looking forward to test it when it released 🎉

@DennisDyallo
Copy link
Collaborator

These should be fixed now @romerod , please get back to me if you run into any issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants