FxSharp going Mono
In this blog post I will tell you my experience porting my open source .NET project to Mono. It’s very easy.
FxSharp is my Expert Advisor System for MetaTrader 4 written in C#. MetaTrader is terminal used by Forex retail trader to enter the transaction. There’s a programming language called MQL. You can use it to create your own expert advisor, but it’s very ancient. Procedural and sucks ! MQL 5 is not a big different with MQL 4. It’s a object oriented language using c++ like syntax. It’s not c++. It’s only like c++. You can see a horrible codes written in this language. C# is better for developer productivity. I use Trade Platform .NET to bridge the MQL into C#. It’s very nice open source project.
First, we need to check out the source code from github.
Change to the directory and you will find solution file. We will build this with xbuild. Before that don’t forget to change the permission of that source code.
After xbuild the solution, you will find that everything is compiled fine.
But when I run it, i ‘ve got this simple and strange error message.
I’m very confused at the first time. Because it doesn’t tell the detail. So I do some googling and found that’s I’m using unsupported API. How do I know which one ?? Finally I found a nice tools called MoMA (The Mono Migration Analyzer)
I download and run it to analyze my application on windows.
Include all the assembly tobe analyzed. You can find guide using MoMA here.
I take a look at the report and found that there’s a problem in entry point.
Seems I use the spesific windows functionality here.
Well, I just need to comment it in the caller.
I run it again and voila. It’s works. My server is running on linux.
Ok. Now I need to connect the Expert Advisors to point to the Linux Servers. First I need to disable the firewall. I don’t want to get caught up setting one by one, so I choose to disable the firewall.
Fill the expert advisors settings. And Ok.
And… Boom. The program is running but seems it can’t load the assembly required for the process. Trade Platform load the assembly dynamically to App Domain. So there’s something wrong with the loading process I think. Why it can’t find the assembly…
Finally I found the problematic codes for loading assembly. It use hardcode to create path for the assembly.
I found a good explanation about the best practice for compatibility between windows and linux. Read this article.
I change the code into something like this. Using method .NET provided.
After push and pull from github. Running it. It’s working now !
The Quarts scheduler, parser, tcp/ip. All the functionality.
It’s very easy to run your .NET application on Linux. Mono is the answer.