views:

1231

answers:

4

Hello!

I wrote an application that uses sqlite and it works great on most of the systems. It is written in C#, and the only non-framework assembly is sqlite, which is included by System.Data.SQLite.dll .

I deploy it the same way on all of the machines (copy pasting the exe file, the database file and the System.Data.SQLite file). It works great for all my PC's and most of the PC's I've tried.

But then I've got reports that for some people it throws the following exception:

Could not load file or assembly 'System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Now I've made sure the dll file is in the same folder than the application exe file. It's the same dll, with the same version as stated in the exception message above.

I was really confused by this, so I created a fresh virtual machine, installed windows 7 professional on it, and just copy pasted the files, and the thing worked. So if it works on a fresh windows, I can't imagine what the other PC's could be missing...

Note: Two of those machines where the project throws the exception are also running windows 7 proffesional.

I would really appreciate any help on this, because I'm fresh out of ideas...

+7  A: 

Here's a possibility: Is the difference between the working and not-working machines 32-bit vs. 64-bit? Are you building for "Any CPU", when you should be building for just the bitness of your external DLL?

RichieHindle
Thank you! Totally missed that sqlite.NET has two different dll files - for x32 and x64. I changed dll's on the machines it didn't work on and it works now. I never thought to ask them about 32 vs 64 bit...
Rekreativc
Is there a way to check at runtime if the platform is 32/64 bit and act accordingly in this case?
Ben
@Ben: I'm afraid I don't know. You'd need to dynamically load the right sqlite DLL at runtime, but I don't know how to do that in .net.
RichieHindle
+1  A: 

It is possible that the machines that throw the exception are running a 64-bit version of Windows and that your program is using the AnyCPU configuration. The System.Data.SQLite DLL is a two-faced beast: a managed part and a native-part. It could be that the native-part is responsible for the exception.

See this question for more info.

typeseven
+1  A: 

Have you checked whether the target system is 64-bit or 32-bit?

It might be that one of your dependencies requires a 32-bit version of Windows. To solve the issue you can specify a platform target in the properties of your C# project: Choose x86 instead of Any CPU.

0xA3
A: 

Check whether you are getting following warning while building Assembly generation -- Referenced assembly 'System.Data.SQLite.DLL' targets a different processor then set appropriate target in you project build setting SQLite entry point not found error

bimbim.in