Click here to Skip to main content
15,851,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the libsodium-net NuGet loaded into my PoC solution and have the 32-bit and 64-bit libsodium.dll files in their respective directories (System32 and SysWOW64). Whenever I go to run the program in debug mode, I get the BadImageFormatException error. Is it enough to have the libsodium.dll files in their respective System directories and I'm just missing something else, or do I need to have copies of those dll files in my solution as well?

Here's my procedure and at least according to intellisense, everything here's hooked up correctly.
Option Explicit On
Imports Sodium
Imports System.Text

Public Class Form1
    Dim textToEncrypt, decrypted As String
    Shared encoder As New UTF8Encoding

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim key, hashedBytes, salt As Byte()

        textToEncrypt = TextBox1.Text
        Dim textBytes As Byte() = encoder.GetBytes(textToEncrypt)
        hashedBytes = CryptoHash.Sha512(textToEncrypt)

        salt = PasswordHash.ScryptGenerateSalt()
        key = SecretBox.GenerateKey()

        Dim passEnc As Byte() = PasswordHash.ScryptHashBinary(textBytes, salt, PasswordHash.Strength.Medium)

        TextBox2.Text = Convert.ToBase64String(passEnc)
        TextBox6S.Text = Convert.ToBase64String(salt)
        TextBox3PBK.Text = Convert.ToBase64String(key)
        TextBox5H.Text = Convert.ToBase64String(hashedBytes)
    End Sub
End Class


What I have tried:

I have tried compiling using both x86 and x64 build configurations since I read here: c# - BadImageFormatException during .Net assembly load issue - Stack Overflow[^] that, that could be the cause of this error but I still got the same error in both areas.

I also tried the answer I found here: How to include libsodium.net on ASP.NET for incorporating libsodium-net into VS[^], where it said to install Visual C++ Redistributable 2015 as well, but the problem there is when I tried that, I got an error from the installer stating that it was already installed on my computer. When I checked though, all I had were the 2008, 2013 and 2017 versions, not 2015, so I'm still at a loss on why I couldn't install the 2015 Redistributable but that's for another time I suppose, unless that's the only solution that will work, in which case, does anyone know what could be causing that issue as well?

I checked in the NuGet manager and both libsodium and Sodium.Core are up to date and running the current stable models. I only mentioned the System32 and SysWOW64 directories because it was something I had tried while trying to find solutions that other people had found and placing the dlls in those directories had solved the issue for one a couple people so I tried it to see if it would solve mine as well, which it didn't.
Posted
Updated 17-May-19 10:19am

1 solution

The 2017 runtime is just an update to the 2015 version. If you install 2017, you have 2015. The version number for 2015 is 14.0 whereas for 2017 it's 14.4.

If you've got 2017 installed, you already have 2015 along with it.


As for you main issue. Not a clue. Every time I've seen that is because you're trying to mix 32- and 64-bit code in the same process.
 
Share this answer
 
Comments
TheOneTrueMongoloid 20-May-19 8:37am    
Thanks for the info on the Visual C++ version. That makes me feel slightly better at least. Do you think completely uninstalling and reinstalling the Sodium-Core and libsodium NuGets would do anything to solve the problem?
Dave Kreskowiak 20-May-19 8:41am    
Nope. Reinstalling almost never solves problems.
TheOneTrueMongoloid 20-May-19 8:54am    
I didn't think so, but when grasping at straws... So, is there a way to tell if I'm pulling from the x64 or x86 bit versions of libsodium from the code editor? I'm still very new to software development at this level (I'm not a dev by trade, so I'm largely self-taught) and as a result, I'm sort of groping in the dark when it comes to defining whether an app is x64 or x86. I have an x86 and x64 platform build profile set up, but since I didn't see where to actually set them up, I had to use the "Copy settings from Any CPU" option when setting them up, and I don't know if that actually did anything. Google hasn't been much help in that department either. Do you have a link to an article that explains that in detail?
Dave Kreskowiak 20-May-19 9:20am    
In Solution Explorer, double-click the Properties node. In the page that pops up, click no the Build tab. You're looking for "Platform target". If it says Any CPU, change it to x86 and build your app and try again.
TheOneTrueMongoloid 20-May-19 9:24am    
It originally said "Any CPU" When I did the first build a few weeks ago but then I created the x86 and x64 build platforms (By copying from from ANY CPU because I didn't see any configurations other than Copy from... and <empty> which didn't seem like a good idea) and no matter if I build to x86 or x64, I still get the same error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900