Failed to load file or assembly "System.Data.SQLite" or one of its dependencies. An attempt was made to download a program with the wrong format

I am trying to use 64-bit Sqlite in my Aspx project. When I run the project, I got the following error:

Failed to load file or assembly 'System.Data.Sqlite or one of its dependencies. An attempt was made to load a program with the wrong format.

I even set Enable 32-Bit Aplications to True to fix the problem, but the problem still persists. I am using .Net 4 Framework . I even downloaded the 64-bit SQlite .dll and included it in my project, and yet it did not solve my problem. What can I do to solve this problem?

Since I could not post the image. I am sending error logs

 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.BadImageFormatException: 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. === Pre-bind state information === LOG: User = SANZ\Administrator LOG: DisplayName = System.Data.SQLite (Partial) WRN: Partial binding information was supplied for an assembly: WRN: Assembly Name: System.Data.SQLite | Domain ID: 36 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/Administrator/Documents/Visual Studio 2010/Projects/StoneCarving/StoneCarving/ LOG: Initial PrivatePath = C:\Users\Administrator\Documents\Visual Studio 2010\Projects\StoneCarving\StoneCarving\bin Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\Administrator\Documents\Visual Studio 2010\Projects\StoneCarving\StoneCarving\web.config LOG: Using host configuration file: 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:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/c78c2519/83a165be/System.Data.SQLite.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/c78c2519/83a165be/System.Data.SQLite/System.Data.SQLite.DLL. LOG: Attempting download of new URL file:///C:/Users/Administrator/Documents/Visual Studio 2010/Projects/StoneCarving/StoneCarving/bin/System.Data.SQLite.DLL. ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated. Stack Trace: [BadImageFormatException: 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.] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144 System.Reflection.Assembly.Load(String assemblyString) +28 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46 [ConfigurationErrorsException: 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.] System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +618 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +209 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178 System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +94 System.Web.Compilation.BuildManager.CallPreStartInitMethods() +332 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +591 [HttpException (0x80004005): 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.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8946484 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97 System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258 
+8
c # sqlite3
source share
4 answers

If you are not using NuGet or prefer to reference sqlite assemblies yourself, make sure that you are using the correct platform version (x64 vs x86).

To support both platforms, you can reference System.Data.SQLite.dll and add two separate folders for each platform for storing SQLite.Interop.dl.

Copying from sqlite official download site:

  • bin \ System.Data.SQLite.dll (required, assembly for managed control only)
  • bin \ x86 \ SQLite.Interop.dll (required, build x86 built-in interaction)
  • bin \ x64 \ SQLite.Interop.dll (x64 embedded assembly required)

With this setting, your application can run on both x64 and x86 platforms. For more information, you can refer to sqlite download site here

+7
source share

Nuget was the final solution for me, I used x64 because I have Windows 8.1 64 bit, but I have to use x86 . after installing System.Data.SQLite enter image description here

+6
source share

If you are using visual studio, try installing through the package manager http://www.nuget.org/packages/system.data.sqlite . This can help with dependency tree issues.

+1
source share

Please help me, how can I use my Windows Form system with SQLite database using mono in Raspberry Pi?

because I got an error if I connected winform to the database

The error appears in the raspberrypi terminal and says:

Could not load file or assembly System.Data.SQLite

0
source share

All Articles