Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Side by Side dependency between C++ and C#

I'm making a browser plugin using FireBreath Framework. Most of logic is written on C# and to call it from browser I've made a C++ wrapper. Browsers call C++ Native code which calls "proxy" Managed C++ code which calls an actual logic in C# project.

So I have 3 dlls:

  • Head native C++ dll which depends on Managed C++;
  • Managed C++ which depends on C#;
  • C# dll which contains main logic.

All 3 dlls installed to a user directory (c:\Users\\AppData\Roaming\MyCompany\MyApp\1.0.0.0)

Problem is browser doesn't load C# dll. I use Side by Side manifest to declare dependencies.

I tried to make a separate manifest file to declare an assembly:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity name="MyAssembly" processorArchitecture="*" type="win32" version="1.0.0.0"/>
    <file name="FirstDependency.dll"/>
    <file name="SecondDependency.dll"/>
</assembly> 

and added link to this dependency to the head dll (Native C++):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <dependency>
    <dependentAssembly>
      <assemblyIdentity name="MyAssembly" processorArchitecture="*" type="win32" version="1.0.0.0"/>
    </dependentAssembly>
  </dependency>
</assembly>

Also I tried to declare dependency directly in the head dll (Native C++):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <file name="FirstDependency.dll"/>
  <file name="SecondDependency.dll"/>
</assembly>

Tried to link dependent dlls using #pragma directive:

 #pragma comment(linker, "\"/manifestdependency:type='win32' name='FirstDependency' version='1.0.0.0' processorArchitecture='X86' language='*'\"")
 #pragma comment(linker, "\"/manifestdependency:type='win32' name='SecondDependency' version='1.0.0.0' processorArchitecture='X86' language='*'\"")

I checked dependencies using Dependency Walker and it confirmed what dependency between Managed C++ and C# doesn't exist.

Plugin has access to the head dll (Native C++) and it loads Managed C++ as well BUT when Managed C++ calls C# dll - plugin fails, C# assembly can't be found.

If I put C# dll in the same directory with browser application (firefox.exe or chrome.exe) - it works.

Looks like Side By Side dependency doesn't work between Managed C++ & C#.

How I can load dependent dlls for my plugin?

like image 737
Andrey Osipov Avatar asked Nov 05 '22 07:11

Andrey Osipov


1 Answers

Solved it.

Added ResolveEventHandler handler to C++/CLI proxy assembly which loads C# assembly from a user directory.

like image 174
Andrey Osipov Avatar answered Nov 09 '22 17:11

Andrey Osipov