0

I wrote a .NET library and this library is called by a VBA macro in a third party application. I used Unmanaged Exports from Robert Giesecke and this part works fine (the library C# code is called, I can step debug inside if I attach to the process, etc).

The problem arises when I need to use types defined in other libraries, for example a WPF GUI that uses Prism Mvvm would need the Microsoft.Practices.Prism.Mvvm assembly. In that case, .NET searches for the assembly but can't find it. Troubleshooting with process monitor, fusion log viewer, I found that the search for the missing assembly is quite short, the only place where the assembly is searched is the application root (e.g. in C:\Program Files\AppName\ ). There is no effort to look in the directory where the dll is, and where the dependencies are. I could copy all the dependencies to the application's root, but that's not a good situation (I don't want to mess into another application's private space)

How do I tell the .NET framework to look at the directory where the DLL is for missing assemblies ?

rienafairefr
  • 364
  • 4
  • 14
  • 1
    If you don't want to use the GAC then you'll have to use the AppDomain.AssemblyResolve event. Subscribing it correctly is not that much joy. Do note that you probably already violate your "can't mess in private space" requirement, not that many good ways to let the native code find your primary assembly either. This is "in for a penny, in for a pound". – Hans Passant Jan 29 '16 at 17:34
  • Thanks Hans, you brought me in the right path I've looked at that appdomain.AssemblyResolve and found this answer: http://stackoverflow.com/a/1373295/1685379 This solves my problem, the assembly gets loaded. The injection in the private space is indeed there, but only through a vba macro with the interface to my dll in it, loaded from yet another folder (which is in user space so not really private anymore anyway) Thanks for the tip ! – rienafairefr Jan 29 '16 at 20:03

1 Answers1

0

See How the Runtime Locates Assemblies (https://msdn.microsoft.com/en-us/library/yx7xezcf%28v=vs.110%29.aspx)

AFAIK .NET will look into the GAC, application's root directory and any private probe paths (Need to be folders inside Application root directory). It does not work like the unmanaged world where you can set the PATH variable and the dll is loaded

Ganesh R.
  • 4,337
  • 3
  • 30
  • 46