oracle “ResolveAssemblyReference”任务失败并出现 System.BadImageFormatException,但未在任何地方使用程序集!

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2507645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:16:31  来源:igfitidea点击:

"ResolveAssemblyReference" task fails and System.BadImageFormatException, but assembly isn't used anywhere!

c#.netoraclebadimageformatexception

提问by bdwakefield

I am getting an error about the assembly "C:\Ora10g\bin\Zip.exe". The trouble is this solution does NOT use anything in Oracle at all. I could not find a single reference to 10g anywhere in the project. I inherited this from another person who left our group. He never had this issue. Another member of my team said he got this before but reinstalling the client portion of 10g fixed it. No such luck there. I even tried using WinGrep to search the entire solution folder for "Ora10g" but it wasn't there.

我收到关于程序集“C:\Ora10g\bin\Zip.exe”的错误。问题是这个解决方案根本不使用 Oracle 中的任何东西。我在项目的任何地方都找不到对 10g 的单一引用。我从另一个离开我们小组的人那里继承了这一点。他从来没有遇到过这个问题。我团队的另一位成员说他以前遇到过这个问题,但重新安装 10g 的客户端部分修复了它。没有这样的运气。我什至尝试使用 WinGrep 在整个解决方案文件夹中搜索“Ora10g”,但它不存在。

Any ideas? I can't build this solution until I can figure out how to get rid of this false reference to Oracle.

有任何想法吗?在我弄清楚如何摆脱对 Oracle 的错误引用之前,我无法构建此解决方案。

VS 2005 solution. Contains a couple WinForm apps, a couple class libraries, and a web service. The error occurs in the main class library project.

VS 2005 解决方案。包含几个 WinForm 应用程序、几个类库和一个 Web 服务。错误发生在主类库项目中。

Here is the error message:

这是错误消息:

Error   1   The "ResolveAssemblyReference" task failed unexpectedly.
System.BadImageFormatException: Could not load file or assembly 'C:\Ora10g\bin\Zip.exe' or one of its dependencies. The module was expected to contain an assembly manifest.
File name: 'C:\Ora10g\bin\Zip.exe'
   at System.Reflection.AssemblyName.nGetFileInformation(String s)
   at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile)
   at Microsoft.Build.Shared.AssemblyNameExtension.GetAssemblyNameEx(String path)
   at Microsoft.Build.Tasks.SystemState.GetAssemblyName(String path)
   at Microsoft.Build.Tasks.Resolver.FileMatchesAssemblyName(AssemblyNameExtension assemblyName, Boolean isPrimaryProjectReference, Boolean wantSpecificVersion, Boolean allowMismatchBetweenFusionNameAndFileName, String pathToCandidateAssembly, ResolutionSearchLocation searchLocation)
   at Microsoft.Build.Tasks.Resolver.ResolveAsFile(String fullPath, AssemblyNameExtension assemblyName, Boolean isPrimaryProjectReference, Boolean wantSpecificVersion, Boolean allowMismatchBetweenFusionNameAndFileName, ArrayList assembliesConsideredAndRejected)
   at Microsoft.Build.Tasks.Resolver.ResolveFromDirectory(AssemblyNameExtension assemblyName, Boolean isPrimaryProjectReference, Boolean wantSpecificVersion, String[] executableExtensions, String directory, ArrayList assembliesConsideredAndRejected)
   at Microsoft.Build.Tasks.AssemblyFoldersResolver.Resolve(AssemblyNameExtension assemblyName, String rawFileNameCandidate, Boolean isPrimaryProjectReference, Boolean wantSpecificVersion, String[] executableExtensions, String hintPath, String assemblyFolderKey, ArrayList assembliesConsideredAndRejected, String& foundPath, Boolean& userRequestedSpecificFile)
   at Microsoft.Build.Tasks.AssemblyResolution.ResolveReference(IEnumerable`1 jaggedResolvers, AssemblyNameExtension assemblyName, String rawFileNameCandidate, Boolean isPrimaryProjectReference, Boolean wantSpecificVersion, String[] executableExtensions, String hintPath, String assemblyFolderKey, ArrayList assembliesConsideredAndRejected, String& resolvedSearchPath, Boolean& userRequestedSpecificFile)
   at Microsoft.Build.Tasks.ReferenceTable.ResolveReference(AssemblyNameExtension assemblyName, String rawFileNameCandidate, Reference reference)
   at Microsoft.Build.Tasks.ReferenceTable.ResolveAssemblyFilenames()
   at Microsoft.Build.Tasks.ReferenceTable.ComputeClosure()
   at Microsoft.Build.Tasks.ReferenceTable.ComputeClosure(DependentAssembly[] remappedAssembliesValue, ITaskItem[] referenceAssemblyFiles, ITaskItem[] referenceAssemblyNames, ArrayList exceptions)
   at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute(FileExists fileExists, DirectoryExists directoryExists, GetDirectories getDirectories, GetAssemblyName getAssemblyName, GetAssemblyMetadata getAssemblyMetadata, GetRegistrySubKeyNames getRegistrySubKeyNames, GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue, GetLastWriteTime getLastWriteTime)
   at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute()
   at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode howToExecuteTask, Hashtable projectItemsAvailableToTask, BuildPropertyGroup projectPropertiesAvailableToTask, Boolean& taskClassWasFound)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

回答by Rob

The give-away's are "The module was expected to contain an assembly manifest" and the fact that the exception is of type System.BadImageFormatException. Something is trying to load the file "C:\Ora10g\bin\Zip.exe" as if it was a .net assembly and it either:

赠品是“该模块应包含程序集清单”以及异常类型为 的事实System.BadImageFormatException。有些东西试图加载文件“C:\Ora10g\bin\Zip.exe”,就好像它是一个 .net 程序集一样,它要么:

  • Isn't a .net assembly
  • Is a .net assembly but for a version of the CLR that is later than the one you're targeting
  • Is a .net assembly, but for the wrong "bitness" (unlikely given the "assembly manifest" part of the exception message).
  • Is corrupted
  • 不是 .net 程序集
  • 是一个 .net 程序集,但对于比您的目标版本晚的 CLR 版本
  • 是一个 .net 程序集,但错误的“位数”(不太可能给出异常消息的“程序集清单”部分)。
  • 已损坏

Have you:

你:

  1. Examined your Solution file (.sln) in a text editor to look for references to this file?
  2. (More likely)Examined the .csproj file for the class library to see if it contains any references to this program? It could be that there's a custom MSBuild task that's trying to load that EXE, possibly to produce ZIPped output from the build process.
  3. Verified that none of the assemblies that you load themselves reference, either directly or indirectly, the Zip.exe file?
  4. As Dave Van den Eynde said, have you checked that the system .targets files (the files that tell MSBuild how to do what it does) are unchanged? You can find these files in %windir%\Microsoft.NET\Framework\v2.0.50727
  1. 在文本编辑器中检查您的解决方案文件 (.sln) 以查找对此文件的引用?
  2. (更有可能)检查类库的 .csproj 文件以查看它是否包含对该程序的任何引用?可能是有一个自定义 MSBuild 任务正在尝试加载该 EXE,可能是为了从构建过程中生成 ZIP 输出。
  3. 确认您加载的所有程序集都没有直接或间接引用 Zip.exe 文件?
  4. 正如Dave Van den Eynde 所说,您是否检查过系统 .targets 文件(告诉 MSBuild 如何做的文件)没有改变?你可以在这些文件中找到%windir%\Microsoft.NET\Framework\v2.0.50727

Other things you can try:

你可以尝试的其他事情:

  1. Follow the instructions in the error message and turn Assembly binding logging on, then review the log to see what Zip.exe was loaded as a dependency of.
  2. "Grep" your whole harddrive for "zip.exe", something, somewhere is referencing it and it may not be in your project/solution (see point 4), but it may be somewhere else that the installer for the Oracle Client has damaged/altered.
  1. 按照错误消息中的说明打开程序集绑定日志记录,然后查看日志以查看 Zip.exe 作为其依赖项加载的内容。
  2. “Grep”你的整个硬盘驱动器“zip.exe”,某处正在引用它,它可能不在你的项目/解决方案中(见第 4 点),但它可能在其他地方 Oracle 客户端的安装程序已损坏/改变。

回答by DCookie

When you reinstalled your Oracle client, where did you put it? If you used the default location from the installer, your ORACLE_HOME will not be at c:\ora10g. Does the directory c:\ora10g\bin exist?

当你重新安装你的 Oracle 客户端时,你把它放在哪里了?如果您使用安装程序中的默认位置,您的 ORACLE_HOME 将不会位于 c:\ora10g。目录 c:\ora10g\bin 是否存在?

A possible workaround is to create the directory c:\ora10g\bin, and copy the zip.exe file from your ORACLE_HOME\bin directory there. There is apparently something in your project that references the Oracle zip binary in that specific location (can't help you there).

一种可能的解决方法是创建目录 c:\ora10g\bin,然后从您的 ORACLE_HOME\bin 目录中复制 zip.exe 文件。您的项目中显然有一些东西在该特定位置引用了 Oracle zip 二进制文件(在那里无法帮助您)。

回答by Ramesh

This file may be referenced by one of your referenced assemblies causing an indirect dependency.

此文件可能被您引用的程序集之一引用,从而导致间接依赖。

Check if the file exisits in the directory and if it does, ensure the file also exists in the build server.

检查该文件是否存在于目录中,如果存在,请确保该文件也存在于构建服务器中。

回答by Dave Van den Eynde

Also, make sure none of the official Targetsfiles were changed. These are automatically imported in your build environment. Perhaps you could do a grep on them as well?

另外,请确保没有更改任何官方Targets文件。这些会自动导入到您的构建环境中。也许你也可以对它们做一个 grep ?

More specifically, your predecessor could have modified them to include some kind of build step into all of his projects.

更具体地说,您的前任可以修改它们以在他的所有项目中包含某种构建步骤。

回答by NotMe

Is your application actually in the c:\ora10g directory? If so .Net is going to try and load every assembly in the \bin directory whether you actually reference it or not.

您的应用程序实际上是否在 c:\ora10g 目录中?如果是这样,.Net 将尝试加载 \bin 目录中的每个程序集,无论您是否实际引用它。