我正在开发一个 Windows 服务,它动态加载一个 DLL,其中包含该服务的实际逻辑。它是使用 Assembly.LoadFrom(...)
加载的。该程序集在 NuGet 上引用 Microsoft.Graph
,而这又需要一些其他库,尤其是 System.ValueTuple
。编译时版本已正确解析,但在加载程序集时它会在存在 4.0.2.0 时尝试查找版本 4.0.1.0。
所以我创建了一个绑定(bind)重定向,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
我启用了 FusionLog,它告诉我它甚至没有加载这个文件(我把它放在名为 .dll.config 的 DLL 旁边)。如何将这些绑定(bind)重定向与 Assembly.LoadFrom()
结合使用?
融合日志(抱歉是德语):
*** Protokolleintrag für Assembly-Binder (06.08.2019 @ 09:14:03) ***
Fehler bei diesem Vorgang.
Ergebnis der Bindung: hr = 0x80070002. Das System kann die angegebene Datei nicht finden.
Der Assemblymanager wurde geladen aus: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Als EXE-Datei ausgeführt. C:\Program Files (x86)\iSM\biCube\services\BiCube.Services.Host.exe
--- Ein detailliertes Fehlerprotokoll folgt.
=== Zustandsinformationen vor Bindung ===
LOG: DisplayName = System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/iSM/biCube/services/
LOG: Ursprünglicher PrivatePath = NULL
LOG: DynamicBase = NULL
LOG: CacheBase = NULL
LOG: AppName = BiCube.Services.Host.exe
Aufruf von Assembly : Microsoft.Graph.Core, Version=1.15.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: Diese Bindung startet im default-Load-Kontext.
LOG: Es wurde keine Anwendungskonfigurationsdatei gefunden.
LOG: Die Hostkonfigurationsdatei wird verwendet:
LOG: Die Computerkonfigurationsdatei von C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config wird verwendet.
LOG: Verweis nach der Richtlinie: System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
LOG: Die Suche im GAC war nicht erfolgreich.
LOG: Download von neuem URL file:///C:/Program Files (x86)/iSM/biCube/services/System.ValueTuple.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/iSM/biCube/services/System.ValueTuple/System.ValueTuple.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/iSM/biCube/services/System.ValueTuple.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/iSM/biCube/services/System.ValueTuple/System.ValueTuple.EXE.
LOG: Fehler bei allen Such-URLs.
最佳答案
它可能与条目有关 -
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.2.0" />
按照只有版本 0 到 4.0.1 将被重定向到 4.0.2。
你应该保留 oldVersion="0.0.0.0-4.0.2.0"
https://stackoverflow.com/questions/57371513/
相关文章:
java - Spring WebFlux : How to access Request Body
python - Tweepy Cursor.items() 无法按预期使用 api.retweet
wordpress - 在 Yoast 生成的 JSON-LD 模式中更改作者 @id
amazon-web-services - Alexa 智能家居技能 : Issue with de
vba - 有没有办法只在启用宏的情况下显示 word 文件的内容?
android-mediacodec - 如何找到 Google Pixel 2 手机的硬件解码器实