.net assembly binding failure

26 views Asked by At

I have the following F# project (RefTest.fsproj, Visual Studio 2022):

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net48</TargetFramework> 

    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <WarnOn>3390;$(WarnOn)</WarnOn>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="File1.fs" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="NinjaTrader.Core">
      <HintPath>..\..\..\..\Program Files\NinjaTrader 8\bin\NinjaTrader.Core.dll</HintPath>
    </Reference>
    <Reference Include="PresentationFramework" />
  </ItemGroup>
</Project>23

The project references a DLL (NinjaTrader.Core.dll)

If I inspect the DLL in ILSpy I get:

// C:\Temp\Ninja\RefTest\RefTest\bin\Debug\net48\NinjaTrader.Core.dll
// NinjaTrader.Core, Version=8.1.2.0, Culture=neutral, PublicKeyToken=0907d8af90186095
// Global type: <Module>
// Architecture: x64
// Runtime: v4.0.30319
// Hash algorithm: SHA1
// Public key: 

If I run SN against the DLL I get:

C:\..> sn -T NinjaTrader.Core.dll

Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

NinjaTrader.Core.dll does not represent a strongly named assembly

The F# project is built successfully and the resulting binary (RefTest.DLL) is referenced dinamically from a process (NinjaTrader.Exe). The process fails to load the DLL with the following Binding logs:

*** Assembly Binder Log Entry  (7/11/2023 @ 10:40:01 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Program Files\NinjaTrader 8\bin\NinjaTrader.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = NinjaTrader.Core, Version=8.1.2.0, Culture=neutral, PublicKeyToken=0907d8af90186095
 (Fully-specified)
LOG: Appbase = file:///C:/Program Files/NinjaTrader 8/bin/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NinjaTrader.exe
Calling assembly : RefTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Program Files\NinjaTrader 8\bin\NinjaTrader.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: NinjaTrader.Core, Version=8.1.2.0, Culture=neutral, PublicKeyToken=0907d8af90186095
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files/NinjaTrader 8/bin/NinjaTrader.Core.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Program Files\NinjaTrader 8\bin\NinjaTrader.Core.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: NinjaTrader.Core, Version=8.1.2.0, Culture=neutral, PublicKeyToken=null
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
LOG: Attempting download of new URL file:///C:/Program Files/NinjaTrader 8/bin/NinjaTrader.Core/NinjaTrader.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/NinjaTrader 8/bin/NinjaTrader.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/NinjaTrader 8/bin/NinjaTrader.Core/NinjaTrader.Core.EXE.
LOG: Attempting download of new URL file:///C:/Users/franco.tiveron/OneDrive/Documents/NinjaTrader 8/bin/Custom/NinjaTrader.Core.DLL.
LOG: Attempting download of new URL file:///C:/Users/franco.tiveron/OneDrive/Documents/NinjaTrader 8/bin/Custom/NinjaTrader.Core/NinjaTrader.Core.DLL.
LOG: Attempting download of new URL file:///C:/Users/franco.tiveron/OneDrive/Documents/NinjaTrader 8/bin/Custom/NinjaTrader.Core.EXE.
LOG: Attempting download of new URL file:///C:/Users/franco.tiveron/OneDrive/Documents/NinjaTrader 8/bin/Custom/NinjaTrader.Core/NinjaTrader.Core.EXE.
LOG: All probing URLs attempted and failed.

The log clearly states why that the binding fails:

WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: The assembly reference did not match the assembly definition found.

The process is looking for a DLL with PublicKeyToken=null, but it finds one with PublicKeyToken=0907d8af90186095. But this doesn't seem correct because the DLL used as reference in RefTes.fsproj has PublicKeyToken=0907d8af90186095 so while is the process willing to load a DLL with PublicKeyToken=null?

How can I fix this issue?

0

There are 0 answers