如何解决编译器错误CS0009-试图加载格式错误的程序?

问题描述 投票:0回答:1

我正在尝试使用reference C#编译器来csc.exe Microsoft ActiveX数据对象6.1库(ADODB),但出现错误:

致命error 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());
  }
}

我尝试了copying the dll to the same folder并引用了它,但遇到了相同的错误。

我也有编译器版本...\v2.0.50727\csc.exe...\v3.5\csc.exe,以及库版本msado20.tlbmsado21.tlbmsado25.tlbmsado26.tlbmsado27.tlbmsado28.tlbmsado60.tlb

当我在Visual Studio 2017(.NET Framework 4控制台应用程序)上尝试相同的方法时,它将起作用。它创建ConsoleApp1\ConsoleApp1\obj\Debug\Interop.ADODB.dll并引用它,但是我不知道它从哪里得到。我尝试在其他文件夹中搜索它。

c# batch-file dll adodb csc
1个回答
0
投票

[我从this thread中找到了Visual Studio使用的文件(通过在线搜索Interop.ADODB.dll file location)以及以后的this link

C:\ Program Files \ Microsoft.NET \ Primary Interop程序集\ 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
© www.soinside.com 2019 - 2024. All rights reserved.