无法加载文件或程序集“System.Data.SQLite”
我已经在 ASP.NET 项目中安装了 ELMAH 1.1 .Net 3.5 x64,现在我收到此错误(每当我尝试查看任何页面时):
无法加载文件或程序集 'System.Data.SQLite,版本=1.0.61.0, 文化=中立, PublicKeyToken=db937bc2d44ff139' 或 它的依赖项之一。 一次尝试 被用来加载一个程序 格式不正确。
描述:一个 期间发生未处理的异常 当前网络的执行 要求。 请检查堆栈跟踪 有关错误的更多信息 以及它在代码中的起源。
异常详细信息: System.BadImageFormatException:可以 不加载文件或程序集 'System.Data.SQLite,版本=1.0.61.0, 文化=中立, PublicKeyToken=db937bc2d44ff139' 或 它的依赖项之一。 一次尝试 被用来加载一个程序 格式不正确。
底部有更多错误详细信息。
我的 Active Solution 平台是“任何 CPU”,我在 x64 Windows 7 上运行,当然是 x64 处理器。 我们使用这个版本的 ELMAH 的原因是因为 1.0 .Net 3.5(x86,这是它编译的唯一平台)在我们的 x64 Windows 服务器上给了我们同样的错误。
我尝试编译 x86 和 x64,但出现相同的错误。 我尝试删除所有编译器输出(bin 和 obj)。 最后,我直接引用了 SQLite dll,这是该项目在服务器上运行不需要的东西,并且出现了以下编译器错误:
错误 1 警告为错误:程序集生成 - 引用的程序集“System.Data.SQLite.dll”针对不同的处理器 MyProject
知道问题可能是什么吗?
更多错误详细信息:
来源错误:
生成了未处理的异常 当前执行期间 网络请求。 有关信息 异常的起源和地点 可以使用异常来识别 下面的堆栈跟踪。
堆栈跟踪:
[BadImageFormatException:无法 加载文件或程序集 'System.Data.SQLite,版本=1.0.61.0, 文化=中立, PublicKeyToken=db937bc2d44ff139' 或 它的依赖项之一。 一次尝试 被用来加载一个程序 格式不正确。]
System.Reflection.Assembly._nLoad(AssemblyName 文件名、字符串代码库、证据 装配安全、装配 locationHint、StackCrawlMark& 堆栈标记、布尔值 throwOnFileNotFound,布尔值 用于内省)+0
System.Reflection.Assembly.nLoad(AssemblyName 文件名、字符串代码库、证据 装配安全、装配 locationHint、StackCrawlMark& 堆栈标记、布尔值 throwOnFileNotFound,布尔值 用于内省)+43
System.Reflection.Assembly.InternalLoad(AssemblyName 装配参考、证据 assemblySecurity、StackCrawlMark& stackMark,用于自省的布尔值) +127 System.Reflection.Assembly.InternalLoad(字符串 汇编字符串,证据 assemblySecurity、StackCrawlMark& stackMark,用于自省的布尔值) +142 System.Reflection.Assembly.Load(字符串 汇编字符串)+28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串 程序集名称,布尔星指令) +46[配置错误异常:可以 不加载文件或程序集 'System.Data.SQLite,版本=1.0.61.0, 文化=中立, PublicKeyToken=db937bc2d44ff139' 或 它的依赖项之一。 一次尝试 被用来加载一个程序 格式不正确。]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串 程序集名称,布尔星指令) +613 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo 艾)+105
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)+178
System.Web.Compilation.BuildProvidersCompiler..ctor(虚拟路径 配置路径,布尔值 支持本地化、字符串 输出程序集名称)+54
System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(布尔值 isPrecompiledApp) +232
System.Web.Compilation.BuildManager.CompileGlobalAsax() +52 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +337[HttpException (0x80004005):无法 加载文件或程序集 'System.Data.SQLite,版本=1.0.61.0, 文化=中立, PublicKeyToken=db937bc2d44ff139' 或 它的依赖项之一。 一次尝试 被用来加载一个程序 格式不正确。]
System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +58 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +512 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager,IApplicationHost appHost, IConfigMapPathFactory 配置MapPathFactory, 托管环境参数 托管参数)+729[HttpException (0x80004005):无法 加载文件或程序集 'System.Data.SQLite,版本=1.0.61.0, 文化=中立, PublicKeyToken=db937bc2d44ff139' 或 它的依赖项之一。 一次尝试 被用来加载一个程序 格式不正确。]
System.Web.HttpRuntime.FirstRequestInit(HttpContext 上下文)+8896783
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext 上下文)+85
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest 写)+259
I've installed ELMAH 1.1 .Net 3.5 x64 in my ASP.NET project and now I'm getting this error (whenever I try to see any page):
Could not load file or assembly
'System.Data.SQLite, Version=1.0.61.0,
Culture=neutral,
PublicKeyToken=db937bc2d44ff139' or
one of its dependencies. An attempt
was made to load a program with an
incorrect format.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, Version=1.0.61.0,
Culture=neutral,
PublicKeyToken=db937bc2d44ff139' or
one of its dependencies. An attempt
was made to load a program with an
incorrect format.
More error details at the bottom.
My Active Solution platform is "Any CPU" and I'm running on a x64 Windows 7 on an x64, of course, processor. The reason why we are using this version of ELMAH is because 1.0 .Net 3.5 (x86, which is the only platform for which it's compiled) gave us this same error on our x64 Windows server.
I've tried compiling for x86 and x64 and I get the same error. I've tried removing the all compiler output (bin and obj). Finally I've made a reference to the SQLite dll directly, something that was not needed for the project to work on the server and I've got this compiler error:
Error 1 Warning as Error: Assembly generation -- Referenced assembly 'System.Data.SQLite.dll' targets a different processor MyProject
Any ideas what the problem might be?
More error details:
Source Error:
An unhandled exception was generated
during the execution of the current
web request. Information regarding the
origin and location of the exception
can be identified using the exception
stack trace below.Stack Trace:
[BadImageFormatException: Could not
load file or assembly
'System.Data.SQLite, Version=1.0.61.0,
Culture=neutral,
PublicKeyToken=db937bc2d44ff139' or
one of its dependencies. An attempt
was made to load a program with an
incorrect format.]
System.Reflection.Assembly._nLoad(AssemblyName
fileName, String codeBase, Evidence
assemblySecurity, Assembly
locationHint, StackCrawlMark&
stackMark, Boolean
throwOnFileNotFound, Boolean
forIntrospection) +0
System.Reflection.Assembly.nLoad(AssemblyName
fileName, String codeBase, Evidence
assemblySecurity, Assembly
locationHint, StackCrawlMark&
stackMark, Boolean
throwOnFileNotFound, Boolean
forIntrospection) +43
System.Reflection.Assembly.InternalLoad(AssemblyName
assemblyRef, Evidence
assemblySecurity, StackCrawlMark&
stackMark, Boolean forIntrospection)
+127 System.Reflection.Assembly.InternalLoad(String
assemblyString, Evidence
assemblySecurity, StackCrawlMark&
stackMark, Boolean forIntrospection)
+142 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, Version=1.0.61.0,
Culture=neutral,
PublicKeyToken=db937bc2d44ff139' 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)
+613 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
+203 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo
ai) +105
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection
compConfig) +178
System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath
configPath, Boolean
supportLocalization, String
outputAssemblyName) +54
System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean
isPrecompiledApp) +232
System.Web.Compilation.BuildManager.CompileGlobalAsax()
+52 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
+337[HttpException (0x80004005): Could not
load file or assembly
'System.Data.SQLite, Version=1.0.61.0,
Culture=neutral,
PublicKeyToken=db937bc2d44ff139' or
one of its dependencies. An attempt
was made to load a program with an
incorrect format.]
System.Web.Compilation.BuildManager.ReportTopLevelCompilationException()
+58 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
+512 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager
appManager, IApplicationHost appHost,
IConfigMapPathFactory
configMapPathFactory,
HostingEnvironmentParameters
hostingParameters) +729[HttpException (0x80004005): Could not
load file or assembly
'System.Data.SQLite, Version=1.0.61.0,
Culture=neutral,
PublicKeyToken=db937bc2d44ff139' or
one of its dependencies. An attempt
was made to load a program with an
incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext
context) +8896783
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext
context) +85
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest
wr) +259
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(20)
System.Data.SQLite.dll
是一个混合程序集,即它同时包含托管代码和本机代码。 因此,特定的 System.Data.SQLite.dll 要么是 x86,要么是 x64,但绝不会同时是两者。更新(由 J. Pablo Fernandez 提供):Cassini,当您按 F5 或单击绿色“播放”按钮时 Visual Studio 使用的开发 Web 服务器,仅是 x86意味着即使您的工作站是 x64,您也只能使用 x86 版本的 System.Data.SQLite.dll。
另一种选择是不使用 Cassini,而使用 IIS7,它是正确的 x64。
System.Data.SQLite.dll
is a mixed assembly, i.e. it contains both managed code and native code. Therefore a particularSystem.Data.SQLite.dll
is either x86 or x64, but never both.Update (courtesy J. Pablo Fernandez): Cassini, the development web server used by Visual Studio when you press F5 or click the green «play» button, is x86 only which means that even if your workstation is x64, you'll only be able to use the x86 version of System.Data.SQLite.dll.
An alternative is not to use Cassini but IIS7 which is properly x64.
确保应用程序池的“启用 32 位应用程序”设置为 false。
Make sure that "Enable 32 - Bit Applications" is set to false for the app pool.
转到
IIS7应用程序池-> 高级设置并将 32 位应用程序设置为 true
。Go to the
IIS7 Application Pool -> advanced settings and set the 32-bit application to true
.如果您不使用 SQLite,这非常简单:
您可以从解决方案的 bin 文件夹中删除 SQLite DLL,然后从引用 ELMAH 的文件夹中删除。 重新构建,您的应用程序将不会尝试加载您未使用的这个 DLL。
This is very simple if you are not using SQLite:
You can delete the SQLite DLLs from your solution's bin folders, then from the folder where you reference ELMAH. Rebuild, and your app won't try to load this DLL that you are not using.
我有一台 64 位开发机器和 32 位构建服务器。 我在 NHibernate 初始化之前使用了这段代码。 在任何架构上都有魅力(以及我测试过的 2 个架构)
希望这对某人有帮助。
吉多
I have a 64 bit dev machine and 32 bit build server. I used this code prior to NHibernate initialisation. Works a charm on any architecture (well the 2 I have tested)
Hope this helps someone.
Guido
我通过安装带有 Nuget 扩展的 System.Data.SQLite 解决了这个问题。 此扩展可用于 Visual Studio 2010 或更高版本。
首先,您必须安装 Nuget 扩展。 您可以在此处进行操作:
其次,现在你可以安装SQLite了:
在程序包管理器控制台中运行命令 Install-Package System.Data.SQLite
现在,您可以使用系统.数据.SQLite。
在本例中,您会看到两个文件夹 x64 和 x86,这些文件夹包含 SQLite.Interop.dll。 现在转到这些 dll 的属性窗口,并将构建操作设置为内容,将复制到输出目录设置为始终复制。
所以,这就是我的方式。
谢谢。
金涛范,
越南胡志明市。
电子邮件:[电子邮件受保护]
I resolved this by installing System.Data.SQLite with Nuget extension. This extension can use for Visual Studio 2010 or higher.
First, you have to install Nuget extension. You can follow here:
Second, now, you can install SQLite:
run the command Install-Package System.Data.SQLite in Package Manager Console
And now, you can use System.Data.SQLite.
In the case, you see two folder x64 and, x86, these folders contain SQLite.Interop.dll. Now go to the properties windows of those dlls and set build action is content and Copy to output directory is Copy always.
So, that is my way.
Thanks.
Kim Tho Pham,
HoChiMinh City, Vietnam.
Email: [email protected]
在我们的例子中不起作用,因为我们的生产服务器缺少
Microsoft Visual C++ 2010 SP1 Redistributable Package (x86)
我们安装了它并且一切正常。 应用程序池必须将“启用 32 位应用程序”设置为 true,并且您必须使用 x86 版本的库
In our case didn't work because our production server has missing
Microsoft Visual C++ 2010 SP1 Redistributable Package (x86)
We installed it and all work fine. The Application Pool must have Enable 32-bit Applications set to true and you must the x86 version of the library
作为一个必须处理 Roadkill Wiki 上相当多具有完全相同问题的错误报告的人,这就是您需要做的:
System.Data.SQLite.dll
System.Data.SQLite.Linq .dll
重新启动时要跳过多少圈真是太痛苦了- 分发 SQLite .NET 二进制文件,我最终的 Roadkill 解决方案是根据您使用的体系结构将正确的二进制文件复制到 ~/bin 文件夹。 不幸的是,这并不能解决 C++ 运行时问题。
As someone who's had to deal with quite a few bug reports on Roadkill Wiki with exactly the same issue, this is what you need to do:
System.Data.SQLite.dll
System.Data.SQLite.Linq.dll
It's a real pain in the ass how many hoops you have to jump through when re-distributing the SQLite .NET binaries, my solution for Roadkill in the end was to copy the correct binaries to the ~/bin folder based on the architecture your using. Unfortunately that doesn't solve the C++ runtime issue.
手动加载相关的 System.Data.SQLite 程序集可以解决此问题。
更改了gatapia的代码如下:
Manual load related System.Data.SQLite assembly can resolve this.
Changed gatapia's Code as below:
当我们的 Windows 服务器从 32 位操作系统转换为 64 位操作系统时,我收到此错误。 引发错误的程序集被设置为在 x86 模式(即 32 模式)下编译。 我将其切换为“任何 CPU”,这样就成功了。 您可以通过执行以下操作来更改此值:
右键单击项目,转到“属性”->“属性”。 构建-> 平台目标-> 更改为“任何CPU”
I got this error when our windows server was converted from 32 bit OS to 64 bit. The assembly that was throwing the error was set to compile in x86 mode (ie 32 mode). I switched it to "Any CPU" and that did the trick. You can change this value by doing the following:
right click on the project go to
Properties -> Build -> Platform Target -> change to "Any CPU"
奇怪的是,我通过 Nuget GUI 应用程序(而不是包管理器控制台)安装 System.Data.SQLite 解决了这个问题。
通过控制台安装不包含该库需要运行的依赖项。
I resolved this, oddly enough, by installing System.Data.SQLite via the Nuget GUI application, as opposed to the package manager console.
Installing via the console didn't include the dependencies this library needs to run.
System.Data.SQLite
依赖于System.Data.SQLite.interop
,请确保两个包的版本相同并且都是 x86。这是一个老问题,但我尝试了以上所有方法。 我正在开发一个严格的x86项目,因此没有两个文件夹/x86、/x64。 但由于某种原因,
System.Data.SQLite
与System.Data.SQLite.interop
是不同的版本,一旦我拉下匹配的 dll,问题就得到了解决。System.Data.SQLite
has a dependency onSystem.Data.SQLite.interop
make sure both packages are the same version and are both x86.This is an old question, but I tried all the above. I was working on a strictly x86 project, so there was not two folders /x86, /x64. But for some reason, the
System.Data.SQLite
was a different version toSystem.Data.SQLite.interop
, once I pulled down matching dlls the problem was fixed.我想出了两个快速解决方案。 要么为我工作。 我认为问题是因为权限。
1)我没有使用 net-2.0 目录中的 Elmah.dll 文件,而是使用 net-1.1 中的 Elmah.dll 。
2)而不是将Elmah.dll保留在项目bin目录中。 我创建了一个dll目录来放置它。
I came up with 2 quick solutions. Either work for me. I think the problem is because of permissions.
1) Instead of using the Elmah.dll file from the net-2.0 directory, I used Elmah.dll from net-1.1 .
2) Instead of keeping Elmah.dll in the project bin directory. I make a dll directory to put it in.
解决此问题的另一种方法是将应用程序升级到 ELMAH 1.2 而不是 1.1。
Another way to get around this is just to upgrade your application to ELMAH 1.2 rather than 1.1.
使用 Visual Studio 2022,我在使用 IIS Express 时将位数设置为 x86 而不是默认值。 这解决了问题,而无需更改任何二进制文件。
Using Visual Studio 2022, I set the Bitness to x86 instead of Default while using IIS Express. That fixed the issue without having to change any binaries.
你能删除你的bin debug文件夹并重新编译吗?
或者检查您的项目对 System.Data.SQLite 的引用,找到它所在的位置,然后在反射器中打开 dll。 如果无法打开它,则意味着 dll 已损坏,您可能需要找到一个正确的 dll 或重新安装 .net 框架。
Can you delete your bin debug folder and recompile again?
Or check your project reference to the
System.Data.SQLite
, track down where it is located, then open the dll in reflector. If you can't open it, that means that the dll is corrupted, you might want to find a correct one or reinstall the .net framework.如果您使用 IIS Express 作为开发计算机上的 Web 服务器,我将更改为本地 IIS。 这对我有用。
If you are using IIS Express as the web server on your development machine I would change to Local IIS. This worked for me.
这是一篇旧帖子,但它可能会帮助一些搜索此错误的人尝试将应用程序池的“启用 32 位应用程序”设置为 True。 这就是为我解决错误的原因。 我通过阅读 @beckelmw 答案的一些评论找到了这个解决方案。
This is an old post, but it may help some people searching on this error to try setting "Enable 32-Bit Applications" to True for the app pool. That is what resolved the error for me. I came upon this solution by reading some the comments to @beckelmw's answer.
您可能安装了错误的软件包。 您需要 Microsoft 生成的包,它实现了 System.Data.Common提供商模型。
You likely have the wrong package installed. You want the package produced by Microsoft which implements the System.Data.Common provider model.
由于所有解决方案都不适合我,我尝试了以下方法:
我删除了这个文件夹 C:\Users....nuget\packages\stub.system.data.sqlite.core.netframework
然后我从 Nuget Package Manager 安装了 System.Data.SQLite.Core
还有“哇!!!” 有用,
As all solutions didn't work for me, I tried this:
I deleted this folder C:\Users....nuget\packages\stub.system.data.sqlite.core.netframework
Then I installed System.Data.SQLite.Core from Nuget Package Manager
And "wow!!!!" it works,