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.

7 commentaires

Siddharth Bhutiya
Siddharth Bhutiya le 19 Sep 2018
Could you post the complete error message that you get when you try to add the assembly without using try-catch.
Also are you able to load it outside MATLAB?
This error could be due to some missing dependencies for your dll. If they are not present in the current folder then MATLAB will not be able to locate them and might throw this error
fablukm
fablukm le 20 Sep 2018
Modifié(e) : fablukm le 20 Sep 2018
Thank you for your reply. I can load (and use) the .dll outside MATLAB. The message is in German (MATLAB UI is in English, but the OS is set to German) and reads
Message: Eine von "mydll.dll" importierte Prozedur konnte nicht geladen werden.
Source: mscorlib
HelpLink:
Which roughly translates to "A procedure imported by mydll.dll could not be loaded."
//EDIT.
>> ex.ExceptionObject.HResult
ans =
int32
-2147024769
Guillaume
Guillaume le 20 Sep 2018
It does sound like a dependency of your library is either not found or for some reason fails to load properly.
fablukm
fablukm le 20 Sep 2018
Modifié(e) : fablukm le 20 Sep 2018
I agree that it seems this way. However, no missing dependencies have been found using DependencyWalker, and I can perfectly use the .dll in C#.
//EDIT I pinned down the problem, but still cannot solve it (see the edit in the original post). Does any of you have experience with a similar issue?
Guillaume
Guillaume le 20 Sep 2018
It's been a long time since I've written dlls and had to contend with dll dependencies so I'm not sure I can be be much help.
All I can do is point you to this tool.
When you tried running it in C# did you add any references ?
There might be files on the linkerpath and inlcudepath which might be needed for your DLL.
Also could you please post the type of the exception object by displaying it after the try catch block.
disp(ex)
This might give us some insights.
fablukm
fablukm le 21 Sep 2018
Here we go:
>> disp(ex)
NetException with properties:
ExceptionObject: [1×1 System.IO.FileLoadException]
identifier: 'MATLAB:NET:CLRException:AddAssembly'
message: 'Message: A procedure imported by "mydll.dll" could not be loaded.↵Source: mscorlib↵HelpLink: '
cause: {}
stack: [0×1 struct]
>> disp(ex.ExceptionObject)
FileLoadException with properties:
Message: [1×1 System.String]
FileName: [1×1 System.String]
FusionLog: [1×1 System.String]
Data: [1×1 System.Collections.ListDictionaryInternal]
InnerException: []
TargetSite: [1×1 System.Reflection.RuntimeMethodInfo]
StackTrace: [1×1 System.String]
HelpLink: []
Source: [1×1 System.String]
HResult: -2147024769
As mentioned in the edits above, mydll.dll depends on hdf5.dll, which is located in the same folder as mydll.dll. Commenting out the calls of hdf5, the assembly works, otherwise I get the aforementioned exception. Could it be that MATLAB is finding another hdf5.dll somewhere else? The folder has been added both to the Windows path and the Matlab path.

Connectez-vous pour commenter.

 Réponse acceptée

fablukm
fablukm le 27 Sep 2018

1 vote

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.

Plus de réponses (0)

Produits

Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by