(bug) Unmanaged C# Export causing Error in Indicators.mqh

 

I suspect this is a threading issue of some sort.

When using an Unmanaged C# Exported assembly and in that C# we access a static variable, over a few calls to OnTick I get an invalid pointer exception in Indicators.mqh line 302.

In C#:

private static int Sum { get; set; }
static UnmanagedExports(){ Sum = 0;}
[DllExport("Bug3AccessOfStaticVariableCausesThreadingIssues", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
static void Bug3AccessOfStaticVariableCausesThreadingIssues(int value)
{
    Sum += value;
}

 In an MQL Expert:

int OnInit()
{
   Bug3AccessOfStaticVariableCausesThreadingIssues(3);
}

 The only way I have found around this is to avoid static variable use in the external assembly and instead use a file.

 
It may be more useful to write in the topic attched to this aricle

 

My problem isn't with the information in the article. I have a C# dll working just fine.

I have simply found some problems with how MT5 interacts with it that I have had to work around. I suspect these problems are MT5 issues and not C# issues so I thought I would see if anyone else has had them, can confirm etc.

 
Get in touch with developers using Service Desk!
  • www.mql5.com
We therefore attach great importance to all user reports about issues in our programs and try to answer each one of them.