向已有依赖v1.1的项目中添加一个依赖v1的项目。

3
这是情况:我有一个项目A,它依赖于库版本1.0.0.0。保持该版本对此项目非常重要。为了获取一些额外的功能,我需要使用库1.1.0.0,所以我创建了一个类库项目,并将较新版本作为依赖项添加到我的主项目中。这样可以很好地工作并编译成功,但在运行时会出现错误:
System.IO.FileLoadException: Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at OpenXMLReportsGenerator.GenerateInvoiceFailureReportHEOpenXML.CreatePackage(String filePath, DataSet data, String exporterName)
   at bDoxWebEd.Reports.InvoiceFailureReportHandler.BeginGenerateReportAndSave(Object gerateReportStateInfo)

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].

当我以 debug 模式编译项目时,不会出现此错误,只有在编译 Release 版本时才会出现。如何解决这个问题?
好的,在服务器上激活函数日志后,我的记录中出现了以下错误:
Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Windows\SysWOW64\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = IIS APPPOOL\bDoxPool
LOG: DisplayName = DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///D:/***/
LOG: Initial PrivatePath = D:\***\bin
Calling assembly : OpenXMLReportsGenerator, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Program Files\Nipendo\bDox\bDox\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/bdox/00aaf85b/66058ca1/DocumentFormat.OpenXml.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/bdox/00aaf85b/66058ca1/DocumentFormat.OpenXml/DocumentFormat.OpenXml.DLL.
LOG: Attempting download of new URL file:///D:/***/bin/DocumentFormat.OpenXml.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

1
按照消息末尾的说明启用绑定日志记录,然后使用 Fuslogvw.exe 检查失败的绑定。 - Panos Rontogiannis
这仅发生在生产环境中,因此我无法从cmd访问Fuslogvw.exe。 - AMember
1
您可以将Fuslogvw.exe复制到生产计算机上。如果无法直接使用,请按照http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx中的说明打开它。 - Panos Rontogiannis
@Panos Rontogiannis,感谢您的提示,我已经从Fusion中添加了日志记录。 - AMember
我已经编辑了你的标题。请参考“问题的标题应该包含“标签”吗?”,在那里达成共识是“不应该”。 - John Saunders
1个回答

2

显然 OpenXMLReportsGenerator,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null 引用程序集 DocumentFormat.OpenXml,Version = 2.0.5022.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35 ,而程序集加载器无法找到它。

尝试将此程序集添加到bin文件夹或GAC中。


1
@AMember 那么您可能需要将程序集添加到全局程序集缓存 (GAC) 中。您能否在问题中提供有关这些程序集的更多详细信息。请指定程序集及其完整名称 (例如 DocumentFormat.OpenXml,Version=2.0.5022.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35) 和它们的依赖项 (引用的程序集)。还请告诉我们哪些程序集是您自己的,哪些是第三方的。 - Panos Rontogiannis
我已经通过更新所有环境的版本来解决了这个问题。无论如何,感谢你的帮助... - AMember

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接