.Net DLL not loading in MT5

 

Hi, I have a mq5 file importing a .Net DLL, that compiles in MetaEditor. When running it in MT5, it shows errors like this:


2022.02.05 17:49:58.337 MT5NetTest (Test2,M1) function 'MT5Net.SampleMT5::Get1DDouble' not found in 'E:\Apps\MT5\MQL5\Libraries\XMT5Net.dll'


Is there a Visual Studio solution available showing this working? Thanks

 
Faisal Mahmood:

Hi, I have a mq5 file importing a .Net DLL, that compiles in MetaEditor. When running it in MT5, it shows errors like this:


2022.02.05 17:49:58.337 MT5NetTest (Test2,M1) function 'MT5Net.SampleMT5::Get1DDouble' not found in 'E:\Apps\MT5\MQL5\Libraries\XMT5Net.dll'


Is there a Visual Studio solution available showing this working? Thanks

it says dll file not found on mql5 libraries you might check if the exist on you libraries folder

 
Rene Taborete Repunte #:

it says dll file not found on mql5 libraries you might check if the exist on you libraries folder

The DLL is there. When DLL is removed error is: "2022.02.06 12:32:01.791 XMT5NetTest (Test2,M1) Cannot load 'XMT5Net.dll' [0]"

 

The reason for this problem comes from the search mechanism of .net assembly. The query sequence when .net is running is roughly as follows: caller's home directory->GAC->CodeBase->application configuration file (not suitable for mt5)

Since the imported .net dll is called by mt5's terminal.exe, when querying the assembly, the caller's home directory will be found, which is the installation directory of mt5. You need to put the referenced dll into this directory.

However, this solution is too ugly, so it is not recommended. It is recommended to use Fody.Costura, which is used to embed all dependent DLLs into the main assembly (usually an EXE or DLL)

The usage of Fody.Costura is also very simple. You only need to install it through nuget, and then compile the assembly as normal.