Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MtApi.MtExecutionException: 'Response from MetaTrader is null' #249

Open
zemuss opened this issue Feb 9, 2021 · 5 comments
Open

MtApi.MtExecutionException: 'Response from MetaTrader is null' #249

zemuss opened this issue Feb 9, 2021 · 5 comments

Comments

@zemuss
Copy link

zemuss commented Feb 9, 2021

MtApi.MtExecutionException
HResult=0x80131500
Message=Response from MetaTrader is null
Source=MtApi
StackTrace:
at MtApi.MtApiClient.SendCommand[T](MtCommandType commandType, ArrayList commandParameters, Dictionary`2 namedParams) in \MtApi\MtApiClient.cs:line 3063

@zemuss
Copy link
Author

zemuss commented Feb 9, 2021

In order to get the application working again I have to relaunch mt4.

@lazou
Copy link

lazou commented Feb 9, 2021

This does also occur sometimes with mt5, but often due to invalid api calls. For example when a parallel call did lead to a disconnect which then results in your mentioned exception. So, the issue is maybe not located in your api call, instead somewhere else.

@zemuss
Copy link
Author

zemuss commented Feb 9, 2021

Ok I used the client GUI that comes with the solution as my starting point and modified as needed. I never really understood why you need to have a chart for each symbol and mtapi ea on each chart. Seems like we can reduce traffic by using a collection send symbols get current bids and asks back in a xml doc.

@zemuss
Copy link
Author

zemuss commented Feb 10, 2021

More details: System.ServiceModel.CommunicationException
HResult=0x80131501
Message=The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
Source=mscorlib
StackTrace:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MTApiService.IMtApi.SendCommand(MtCommand command)
at MTApiService.MtApiProxy.SendCommand(MtCommand command) in \MTApiService\MtApiProxy.cs:line 31

This exception was originally thrown at this call stack:
[External Code]
MTApiService.MtApiProxy.SendCommand(MTApiService.MtCommand) in MtApiProxy.cs

@jdufaud
Copy link

jdufaud commented Feb 24, 2021

I have a fix for you, use a lock in the Execute method.
If you are making a lot of call at the same time this exception can bell called

private static readonly object objLock = new object();

private static async Task<TResult> Execute<TResult>(Func<TResult> func)
{
            return await Task.Factory.StartNew(() =>
            {
                lock(objLock)
                {
                    var result = default(TResult);
                    try
                    {
                        result = func();
                    }
                    catch (ExecutionException ex)
                    {
                        Console.WriteLine($"Exception: {ex.ErrorCode} - {ex.Message}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Exception: {ex.Message}");
                    }
                    return result;
                }
            });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants