[英]How can i fix "error CS0009: Metadata file "System.Xml.dll' could not be opened -- Image is too small"?
[英]How to fix the compiler error CS0009 - An attempt was made to load a program with an incorrect format?
我正在嘗試使用csc.exe C# 編譯器引用Microsoft ActiveX 數據對象 6.1 庫 (ADODB),但出現錯誤:
致命錯誤 CS0009 :無法打開元數據文件“c:\\Program Files\\Common Files\\system\\ado\\msado15.dll”——“嘗試加載格式不正確的程序。 '
我已簡化文件以嘗試跟蹤問題。
批處理文件Compile.bat
:
@ECHO OFF
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\csc.exe -nologo -r:"C:\Program Files\Common Files\system\ado\msado15.dll" Code.cs
PAUSE >NUL
C# 文件Code.cs
:
class Program {
static void Main() {
ADODB.Connection ADODBConnection = new ADODB.Connection();
System.Console.WriteLine((ADODBConnection == null).ToString());
}
}
我曾嘗試將 dll 復制到同一個文件夾並引用它,但遇到了同樣的錯誤。
我也有編譯器版本...\\v2.0.50727\\csc.exe
和...\\v3.5\\csc.exe
以及庫版本msado20.tlb
、 msado21.tlb
、 msado25.tlb
、 msado26.tlb
、 msado27.tlb
、 msado28.tlb
和msado60.tlb
。
當我在 Visual Studio 2017(.NET Framework 4 控制台應用程序)上嘗試相同時,它可以工作。 它創建ConsoleApp1\\ConsoleApp1\\obj\\Debug\\Interop.ADODB.dll
並引用它,但我不知道它從哪里得到它。 我嘗試在不同的文件夾中搜索它。
我從這個線程中找到了 Visual Studio 使用的文件(通過在線搜索Interop.ADODB.dll file location
)和后來的這個鏈接:
C:\\Program Files\\Microsoft.NET\\Primary Interop Assemblies\\adodb.dll
工作Compile.bat
:
@ECHO OFF
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\csc.exe -nologo -r:"%ProgramFiles%\Microsoft.NET\Primary Interop Assemblies\adodb.dll" Code.cs
PAUSE >NUL
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.