Archived Forum Post

Index of archived forum posts

Question:

64bit - Could not load file or assembly 'ChilkatDotNet4' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Feb 08 '17 at 10:00

In a web application, the following error shows up when browsing to a page that instantiates a Chilkat object. Could not load file or assembly 'ChilkatDotNet4' or one of its dependencies. An attempt was made to load a program with an incorrect format.

code behind : protected void Page_Load(object sender, EventArgs e) { Chilkat.Crypt2 c = new Chilkat.Crypt2(); }

Windows7 64bit / VS2010 v10.0.30319.1 / ASP.Net v4.0.30319.272

Thanks


Accepted Answer

It's a 32-bit vs. 64-bit mismatch. It means you are trying to load a 64-bit .NET assembly into a 32-bit process, or the reverse (a 32-bit assembly into a 64-bit process).

Here are possible solutions:

1) Target your app for x86 instead of "Any CPU". If you do this, then your application will run as a 32-bit process regardless of the machine architecture and you may always use the 32-bit Chilkat assembly.

2) If you really need to target "Any CPU", then make sure to deploy the 32-bit Chilkat assembly w/ your app on 32-bit systems, and deploy the 64-bit Chilkat assembly to 64-bit systems.

3) If your app is running within ASP.NET or a Windows Service and you're not quite sure whether it's 32-bit or 64-bit, then install the 32-bit Chilkat assembly in the 32-bit GAC (Global Assembly Cache), and also install the 64-bit Chilkat assembly into the 64-bit GAC. The .NET runtime will automatically look in the correct GAC and will find the correct assembly.


Answer

Thanks for the suggestions.

Solved the problem 'my way': Opened the small sample project, just built to test the FTP functions of the downloaded Chilkat .Net dll.

Loaded all modules & forms from the full project into the test project. Changed the startup object, adjusted some of the libraries & everything runs just fine.

Only project renaming & deleting of the test module still needs to be done.

Have no idea why I got that error in the main project & will most likely never know.

Thanks again, Peter K


Answer

+1 for enable 64b IIS Express, this is what I have been looking for.

Tools > Options > Projects and Solutions > Web Projects. There is a checkbox to enable 64b it IIS


Answer

How do you know if you have the 32 bit or 64 bit version?


Answer

In your C# program, you can do this:

if (IntPtr.Size == 4)
{
    // 32-bit
}
else if (IntPtr.Size == 8)
{
    // 64-bit
}
else
{
    // Getting here is not possible..
}


Answer

Also..

For now, the best way to know which ChilkatDotNet46.dll you have is to either keep track of what you downloaded from chilkatsoft.com, or you can download both 32-bit and 64-bit and compare the DLL sizes. The larger one is the 64-bit build.

Starting with the next version of Chilkat (v9.5.0.66), I'm going to identify the bitness (32-bit or 64-bit) in the Version resource of the DLL. This way, you can right-click on the DLL and examine the properties, then go to the Details tab, and you'll see either "64-bit" or "32-bit" in the description.