0

My native program is temp/A/prog.exe. I am loading a .Net assembly using Assembly::Load() in C++/CLI at temp/B/LoadAssem.dll. But assem.dll references dynAssem.dll located in temp/C. I have written the config file as follows:

<configuration>  
   <runtime>  
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
       <dependentAssembly>  
         <assemblyIdentity name="DynAssem"  
                           publicKeyToken="xxxxx"  
                           culture="neutral" />  
         <codeBase version="0.0.0.0" href="../C/DynAssem.dll"/>  
       </dependentAssembly>        
      </assemblyBinding>  
   </runtime>  
</configuration>

But the bind fails with fusion output as follows:

=== Pre-bind state information ===
LOG: DisplayName = dynAssem
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: dynAssem | Domain ID: 1
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:/temp/A/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = prog.exe
Calling assembly : XXX, Version=0.0.0.0, Culture=neutral, PublicKeyToken=XXX.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\temp\A\prog.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: 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:/temp/A/dynAssem.DLL.
LOG: Attempting download of new URL file:///c:/temp/A/dynAssem/dynAssem.DLL.
LOG: Attempting download of new URL file:///c:/temp/A/dynAssem.EXE.
LOG: Attempting download of new URL file:///c:/temp/A/dynAssem/dynAssem.EXE.
LOG: All probing URLs attempted and failed.

I understand this directory layout is not the preferred layout for .NET. However, I need to support multiple other languages, therefore the directory structure and assembly locations cannot be changed.

Dula
  • 1,404
  • 1
  • 14
  • 29

1 Answers1

0

You might hope this would be possible with the probing element in the app.config (see https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/probing-element)

<configuration>  
   <runtime>  
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
        <probing privatePath="../C/"/>  
       <dependentAssembly>  
         <assemblyIdentity name="DynAssem"  
                           publicKeyToken="xxxxx"  
                           culture="neutral" />  
         <codeBase version="0.0.0.0" href="../C/DynAssem.dll"/>  
       </dependentAssembly>        
      </assemblyBinding>  
   </runtime>  
</configuration>

but it appears (at least according to Probing the assembly from parent directory of the exe) that it's not possible to probe in folders higher in your folder hierarchy.

EDIT:

As described here (https://blogs.msdn.microsoft.com/suzcook/2003/05/29/choosing-a-binding-context/) you can use LoadFrom to load assemblies from any path you like, I haven't tried it but that could be your solution.

Jim W
  • 4,866
  • 1
  • 27
  • 43