MATLAB: HDF5.dll version conflict between MCR 9.1 and the application

hdf5 .net

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?

Best Answer

There is no getting around it. HDF5.dll is native. All users of HDF5.dll in a given process must use the same version.