addinSpy警告找不到DLL路径。我的dll或GAC中的汇编问题

时间:2014-03-21 09:49:29

标签: c# .net .net-assembly excel-addins

我有一个Excel插件。这取决于我在GAC注册的Assmbly。

addinSpy发出此警告(抱歉格式不正确)

Add-in DLL path is not found. System.BadImageFormatException: Could not load file or assembly 'file:///C:\Program Files (x86)\Poly\PolyAddins\PolyExcel\DBExcelAddin.dll' or one 

of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'file:///C:\Program Files (x86)\Poly\PolyAddins\PolyExcel\DBExcelAddin.dll'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean 

throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean 

throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean 

forIntrospection, StackCrawlMark& stackMark)
at System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile)
at AddInSpy.AssemblyScanner.GetAssemblyInfo(String fileName, String hostName, Boolean isVstoAddIn)

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  C:\Users\MCH02080\Downloads\AddInSpy.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Username
LOG: Where-ref bind. Location = C:\Program Files (x86)\Poly\PolyAddins\PolyExcel\DBExcelAddin.dll
LOG: Appbase = file:///C:/Users/XXXXXXXX/Downloads/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).

LOG: This is an inspection only bind.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Poly/PolyAddins/PolyExcel/DBExcelAddin.dll.
ERR: Failed to complete setup of assembly (hr = 0x8013101b). Probing terminated.

我特别不明白"尝试下载新的URL文件:/// C:/ Program Files(x86)/Poly/PolyAddins/PolyExcel/DBExcelAddin.dll。"失败,因为那正是它的确切位置。

所以我认为Fusion是下一步尝试解决发生的事情。

*** Assembly Binder Log Entry  (21.03.2014 @ 10:07:51) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = MyUserName
LOG: DisplayName = DBExcelAddin, Version=1.1.9.0, Culture=neutral, processorArchitecture=MSIL
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: DBExcelAddin, Version=1.1.9.0, Culture=neutral, processorArchitecture=MSIL | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Program Files (x86)/Poly/PolyAddins/PolyExcel/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = EXCEL.EXE
Calling assembly : (Unknown).

LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Poly/PolyAddins/PolyExcel/DBExcelAddin.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Program Files (x86)\Poly\PolyAddins\PolyExcel\DBExcelAddin.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: DBExcelAddin, Version=1.1.9.0, Culture=neutral, PublicKeyToken=null
LOG: A partially-specified assembly bind succeeded from the application directory. Need to re-apply policy.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
WRN: A duplicate assembly was found while copying the assembly item to the cache.
LOG: Binding succeeds. Returns assembly from C:\Users\Username\AppData\Local\assembly\dl3\AB9LQY47.X7Y\AANNZTWA.2TD\2f8e8cc8\00da0eb0_3141cf01\DBExcelAddin.dll.
LOG: Assembly is loaded in default load context.

我很肯定它告诉我该怎么做,但我不明白,所以请你告诉我。

1 个答案:

答案 0 :(得分:4)

  

System.BadImageFormatException:无法加载文件或程序集......

这不是警告,而是错误。 BadImageFormatException就是结果。这个“addinSpy”实用程序为您提供了很差的诊断功能,实际上找到的文件很好。它只是无法加载,CLR在尝试加载程序集时抛出了BadImageFormatException。

  

装配管理器从以下位置加载:C:\ Windows \ Microsoft.NET \ Framework \ v2.0.50727

这是导致异常的原因,请注意.NET Framework的版本号2.0.50727。这是一个糟糕的版本,你的程序集需要.NET 4.0版本的框架才能正确加载和执行。 CLR v2不知道如何加载v4程序集。

这通常是臭名昭着的CLR版本注入问题。无论首先加载什么加载项,都会确定将哪个版本的CLR加载到Office程序中。如果这是一个旧版本,比如v2.0.50727,你会有祸了吗。之后加载并需要更高版本的任何加载项注定无法加载。 BadImageFormatException是诊断。

你的Fuslogvw.exe提供了一个非常强烈的提示,它实际上是你的“addinSpy”实用程序导致问题。相当具有讽刺意味的是,您需要找到一个使用.NET v4的程序更新。或者只是退休并坚持使用Fuslogvw.exe。

此问题的一般解决方案是始终强制加载最新版本的CLR,即使加载项要求使用早期版本也是如此。这需要一个名为Excel.exe.config的.config文件,并将其复制到Excel.exe所在的同一目录中。它需要看起来像这样:

<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0"/>
    </startup>  
</configuration>
相关问题