MATLAB: .NET addAssembly fail

addassemblydllhdf5loaderexceptionsMATLABnetsystem variables

The code
A = NET.addAssembly('C:\path\to\mydll.dll')
fails with the hint 'source: mscorlib'.
After some searching, I tried to capture the exception using
try
NET.addAssembly('C:\path\to\mydll.dll')
catch ex
end
But the ex.ExceptionObject has no field LoaderException:
>>> ex.ExceptionObject.LoaderExceptions.Get(0).Message
No appropriate method, property, or field 'LoaderExceptions' for class 'System.IO.FileLoadException'.
How can I get access to the LoaderException?
//EDIT: I pinned it down: mydll.dll depends on a version of hdf5.dll which is situated in the same folder as mydll.dll. If I comment out all statements relying on hdf5.dll from the source of mydll.dll, the import works. Could it be that MATLAB is working with another version of hdf5.dll it found somewhere else? I tried 1) adding the folder with my version to the path 2) copying hdf5.dll to /system32.

Best Answer

Problem solved: As it seemed, there was a version clash with another dll, in this case, hdf5.dll and hdf5_hl.dll. MATLAB has its own versions, which are stored in
...\MATLAB\R2018a\bin\win64
To solve the issue, I replaced my versions of the aforementioned hdf5-related dlls by the ones stored in the MATLAB folder. However, I could not compile my own .dll anymore, because of an obvious hdf5-version clash.
To solve this, there is a Windows system variable called DISABLE_HDF5_VERSION_CHECK which needs to be set to 1 for my .dll to compile. The compiler still returns a warning, but I just needed to save and load a hdf5 file, which almost any version can do.
To turn it on, proceed the following way: [e.g. Start > Windows Control Panel > ] System Settings > Advanced system settings > Environment Variables > New System Variable > Variable name: DISABLE_HDF5_VERSION_CHECK, Value: 1.
Thank you very much for your help. As a suggestion, it would be comfortable for us clients if in a future version, MATLAB could indicate at least the source of such a version clash somewhere in the exception or in an error message. It was pretty cumbersome to find it on my own.