Load binding redirects from *.dll.config when loading an assembly dynamically

0

I'm developing a windows service that is dynamically loading an DLL which contains the actual logic for that service. It is loaded using Assembly.LoadFrom(...). That assembly is referencing Microsoft.Graph on NuGet which in turn requires some other libraries, System.ValueTuple in particular. When compiling the versions are resolved properly, but when loading the assembly it tries to find version 4.0.1.0 when 4.0.2.0 is present.

So I created a binding redirect like follows:

<?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>

I enabled FusionLog and it told me it wasn't even loading this file (I put it next to the DLL with the name .dll.config). How can I use those binding redirects in connection with Assembly.LoadFrom()?

The fusion log (sorry it's german):

*** 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.
c#
visual-studio
asked on Stack Overflow Aug 6, 2019 by S. Mense

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0