简体   繁体   中英

MVC3 app - getting “Could not load file or assembly 'System.Data.SQLite' or one of its dependencies.”

The problem:

I'm building ac# 4.0, MVC 3 based web app. I'm using SQLite as a database.

When I start the app, I get this error:

Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made to load a program with an incorrect format.

This is the fusion assembly load trace:

=== Pre-bind state information ===
LOG: User = Steve-PC\Steve
LOG: DisplayName = System.Data.SQLite
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Data.SQLite | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/Steve/Documents/Visual Studio 2010/Projects/EMMA3/EMMA_Web/
LOG: Initial PrivatePath = C:\Users\Steve\Documents\Visual Studio 2010\Projects\EMMA3\EMMA_Web\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Steve\Documents\Visual Studio 2010\Projects\EMMA3\EMMA_Web\web.config
LOG: Using host configuration file: C:\Users\Steve\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Steve/AppData/Local/Temp/Temporary ASP.NET Files/root/6454c2d1/d37faccb/System.Data.SQLite.DLL.
LOG: Attempting download of new URL file:///C:/Users/Steve/AppData/Local/Temp/Temporary ASP.NET     Files/root/6454c2d1/d37faccb/System.Data.SQLite/System.Data.SQLite.DLL.
LOG: Attempting download of new URL file:///C:/Users/Steve/Documents/Visual Studio 2010/Projects/EMMA3/EMMA_Web/bin/System.Data.SQLite.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

I am using:

Windows 7 x64 Visual Web Developer 2010 IIS Express 7.5 System.Data.SQLite x64 1.0.77.0

I've Googled around a lot and the general thought seems to be that this is related to running a 32 bit assembly on a 64 bit system or vice versa.

Things I've tried:

  1. Switch to IIS Express from the VS built in web server. Apparently the built in server can only cope with 32bit applications and IIS Express can do both. No change.
  2. Make sure you're using the 64 bit version of SQLite. Originally, I was using the regular version but changing to the 64 bit version does not seem to help.
  3. Enable the '32 bit app on win 64' setting in IIS. (In IIS express, this is done using appcmd.exe - appcmd set apppool /apppool.name: "" /enable32bitapponwin64:true). Again, this made no change.
  4. Uninstall/reinstall Sqlite. No change.
  5. Create a simpler version of the project to make sure everything is clean and narrow down the cause. This lead me to the 'steps to reproduce' below but hasn't really helped me.

Steps to reproduce:

  1. Create new MVC 3 web project.
  2. Run it and see that it works.
  3. Use Nuget to add a reference to SQLite x64.
  4. Run site again and it will give this error.

So in summary - I'm getting the error above, it's definitely due in some way to SQLite, I seem to have everything 64 bit, but it still doesn't work. Any ideas?

Thanks in advance.

If you get this error when attempting to run the web application from within VisualStudio, then it is because the built-in webserver is 32-bit only. If you wish to debug / run with 64-bit from within VisualStudio, check out the Cassini project. There are instruction to build a 64-bit version of cassini and use it instead of the VisualStudio default web-server.

Figured this out some time ago and forgot about this question.

The answer was to remove SQLite x64 and install SQLite x86... Simple as that. Seems weird when I'm building a 64 bit assembly on a 64 bit version of windows but there we go. The class libraries that actually have the data access logic still reference the 64 bit version of SQLite but for some reason the actual web project has to reference the 32 bit version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM