0

I have a managed C# application that loads managed plugins. Depending on a condition I want to be able to run some code on assembly load that will monkey patch the host application to hook some methods.

I tried using module initializers but the .cctor is not called until it tries to reference something in the DLL.

I have seen the answers for C# equivalent of DllMain in C (WinAPI) but none works for me

(this DLL must be a managed DLL; this answer C# equivalent of DllMain in C (WinAPI) won't work as the host application expects to find some managed classes based on an attribute and what I'll have is a native dll.)

Please note that I can not modify the host application.

MemCtrl
  • 131
  • 1
  • 11
  • I am pretty sure you will be able to put some CLR classes into the wrapper assembly which you create using the post you have mentioned. Of course it can be a little bit pain or duplicate work, but if you can't modify your host application, I don't think you have another option. On the other hand, if you only need to specify some descriptive classes for your host application, it can work very well. – vasek Jun 27 '17 at 13:44
  • I am willing to do this but will loading a mixed mode assembly from a **managed** application call its DllMain function? – MemCtrl Jun 27 '17 at 13:47
  • I think it should, but never tried that. Actually, what is the reason you want to achieve this? What would you put into your 'hacked' DllMain function? – vasek Jun 27 '17 at 13:53
  • 2
    https://learn.microsoft.com/cs-cz/cpp/dotnet/initialization-of-mixed-assemblies – vasek Jun 27 '17 at 13:57

0 Answers0