Importing C# DLL into MQL5 script

 

I want to import my dll program written in VS C# which runs OK, into mql5 script. Here is what i have done. but after compiling in mql5 I get following the error:

Cannot find 'Program' in 'Keygen.dll'
unresolved import function call

Would you help me how to do the binding?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace Keygen
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form2());
        }
    }
}
#property strict

#import "Keygen.dll"
void Program();
#import
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   Program();
  }
//+------------------------------------------------------------------+
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
  • www.mql5.com
A purchased licensed version allows at least 5 activations. The number of activations is specified by seller. Seller may increase the allowed number of activations
 

You cannot use #import for managed DLLs (.NET class library).

 
I had the same problem. And finally I figured it out. Assembly name, default namespace in project property and namespace name must be the same !! but class name must be different! then everything will work as it should.
Reason: