MyApp is a C# .NET v4.5.2 WPF app. MyAssembly is a Matlab .NET assembly I created containing MyClass. MyAssembly requires MCR v9.1. MyApp performs various tasks; when one requires Matlab and it tries to instantiate MyClass then a popup window displays:
The procedure entry point H5Rdereference could not be located in dynamic link library C:\Program Files\MATLAB\MATLAB Runtime\v91\bin\win64\libmat.dll.
MyApp contains a version of hdf5.dll (obtained from Nuget package HDF.PInvoke v1.10.1), and I discovered that MCR 9.1 also contains a (different) version of hdf5.dll in C:\Program Files\MATLAB\MATLAB Runtime\v91\bin\win64. When I replaced MyApp's version of that dll with MCR 9.1's version, MyApp is able to instantiate MyClass, but then MyApp is no longer able to perform its HDF5 tasks; calls to H5.open() throw:
Unable to load DLL 'hdf5.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'
MyClass doesn't require HDF5, so why is the MCR loading its copy of that DLL? How do I get around this conflict?
Update 1: I moved all of MyApp's non-Matlab-related use of HDF5 into a separate app domain, but the problem persists. It is as if HDF5.dll is getting loaded into the primary app domain even though the code that loads it is executing in a separate app domain.
HDF5.dll is a native DLL and thus not bound by AppDomain boundaries.