C# 调用SQLite报错:System.BadImageFormatException:Could not load file or assembly ...

新建的winform项目,调用连接sqlite,报错提示:

System.BadImageFormatException:'Could not load file or assembly 'System.Data.SQLite, Verison=1.0.60.0, Cultrue=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. An attempt was made to load a program with an incorrect format.'

探索一番之后,找到了原因与解决方法:

原因:System.Data.SQLite.DLL的版本问题

解决方法:

1. build的目标平台和System.Data.SQLite.DLL的保持一致。选了x86就用32位版的dll,选了x64就用64位版的dll。

2. 在配置文件中添加<startup>项,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

问题解决:

扫描二维码关注公众号,回复: 5347808 查看本文章

猜你喜欢

转载自blog.csdn.net/zhouyingge1104/article/details/87934814