【问题标题】: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.Data.SQLite”或其依赖项之一。试图加载格式不正确的程序
【发布时间】:2014-07-04 08:06:27
【问题描述】:

我正在尝试在我的 Aspx 项目中使用 64 位 Sqlite。运行项目时,出现以下错误:

无法加载文件或程序集“System.Data.Sqlite”或其其中之一 依赖关系。试图加载一个不正确的程序 格式。

我什至将Enable 32-Bit Aplications 设置为True 来解决问题,但问题仍然存在。我正在使用.Net 4 Framework。我什至下载了64-bit SQlite .dll 并将其包含在我的项目中,但它仍然没有解决我的问题。我该怎么做才能解决这个问题?

因为我无法发布图片。我正在发布错误日志

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

【问题讨论】:

  • 您是否将程序专门编译为 64 位?如果没有,无论何时以 32 位运行它都会出现此错误。
  • 您托管的是哪个版本的 IIS?
  • 将您的问题标题粘贴到 Google 会显示:stackoverflow.com/questions/1278929/…。很可能,您的问题与此重复。

标签: c# asp.net sqlite


【解决方案1】:

如果您不使用 NuGet 或更喜欢自己引用 sqlite 程序集,请确保使用正确的平台版本(x64 与 x86)。

要支持这两个平台,您可以引用 System.Data.SQLite.dll,并为每个平台添加 2 个单独的文件夹来保存 SQLite.Interop.dl。

从官方sqlite下载网站复制:

  • bin\System.Data.SQLite.dll(必需的,仅限托管的核心程序集)
  • bin\x86\SQLite.Interop.dll(必需,x86 本机互操作程序集)
  • bin\x64\SQLite.Interop.dll(必需,x64 本机互操作程序集)

通过此设置,您的应用可以在 x64 和 x86 平台上运行。 更多详细信息可以参考sqlite下载站here

【讨论】:

    【解决方案2】:

    Nuget 是我的最终解决方案,我使用的是 x64,因为我有 windows 8.1 64 位,但是 我应该使用 x86。一旦安装 System.Data.SQLite

    【讨论】:

    • 感谢您的建议!它帮助了我。
    【解决方案3】:

    如果您使用的是 Visual Studio,请尝试通过包管理器 http://www.nuget.org/packages/system.data.sqlite 进行安装。这可能有助于解决依赖关系树问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-11
      • 2017-09-22
      • 2013-02-27
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多