Dismiss Notice
We would like to remind you that we’re updating our login process for all 3CX forums whereby you will be able to login with the same credentials you use for the Partner or Customer Portal. Click here to read more.

Error using OMsamples

Discussion in 'CRM / Helpdesk / App Integration' started by Apereira, Aug 1, 2016.

Thread Status:
Not open for further replies.
  1. Apereira

    Joined:
    Jul 23, 2016
    Messages:
    12
    Likes Received:
    0
    Hi,

    Trying to get 3CX to report us live information about what is happening on our customers 3CX.

    So I've installed 3cx v15 on my machine(windows 10 64bit) so I can do some tests.

    When running OMSamples, I get the error.

    In fact, according to the documentation, this key is present in the dictionary.

    Can someone please help?
     
  2. Apereira

    Joined:
    Jul 23, 2016
    Messages:
    12
    Likes Received:
    0
    Adding more information.

    Tried to replicate the code from "Add extension", and got the following error.


    On line

    Code:
    PhoneSystem ps = PhoneSystem.Root;
     
  3. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,614
    Likes Received:
    126
    The exception BadImageFormatException looks like a bitness mismatch. That means, your app is x86 and tries to load an x64 assembly. Check if your application is x86, in that case change it to AnyCPU or x64.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Apereira

    Joined:
    Jul 23, 2016
    Messages:
    12
    Likes Received:
    0
    Thanks for your reply,

    I've tried this and when I try to remove an extension I don't get output.

    although this looks like it still not working.


    I've created a test extension number 501

    command I am trying to run

    Code:
    OMSamples.exe remove_extension 501


    On the other way, when trying to use my app.

    Now I get

     
  5. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,614
    Likes Received:
    126
    That DLL is in folder "C:\Program Files\3CX Phone System\Bin". Copy it to your project output folder.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Apereira

    Joined:
    Jul 23, 2016
    Messages:
    12
    Likes Received:
    0
    Tried that before with no luck.

    On my output folder, I have,

    3CXPhoneSystem.ini
    tcxpscom_native.dll



    And I've added a reference for 3cxpscomcpp2 that is located on "C:\Program Files\3CX Phone System\Bin"


    Do I need to move also this file to my output folder and add it as a reference from there?
     
  7. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,614
    Likes Received:
    126
    In your reference set CopyLocal to true, and that will copy the DLL to your output folder.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Apereira

    Joined:
    Jul 23, 2016
    Messages:
    12
    Likes Received:
    0
    It was already set to true.

    That's weird, looks like it is trying to get the file from a different path.

    Error:

     
  9. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,614
    Likes Received:
    126
    Check if your program is executing with the current directory set to the exe location. Sometimes it runs for example in C:\windwos\system32. Try debugging the app and check the value of "System.IO.Directory.GetCurrentDirectory()" or "Application.StartupPath".
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. Apereira

    Joined:
    Jul 23, 2016
    Messages:
    12
    Likes Received:
    0
    yes, it is running on the Debug folder where the files are located.

    The issue is that the documentation is not that clear about what to do.

    Tried also to add the DLL's to the project and still with the same output.
     
  11. Apereira

    Joined:
    Jul 23, 2016
    Messages:
    12
    Likes Received:
    0
    After a few attempts still having the same issue, it states that it can't load the other DLL.
     
  12. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,614
    Likes Received:
    126
    Did you also copy the sl.dll library? Just in case copy all the dlls from 3cx installation to your app folder, because maybe the problem is not the mentioned dll but a dependency.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. Apereira

    Joined:
    Jul 23, 2016
    Messages:
    12
    Likes Received:
    0
    Great! Looks like it worked cause is not returning me any error now.

    Although this, it is not returning me any information from the 3Cx installation

    I've used the code from the example to try to list all the extensions and some other information as an example.

    But it is not returning them.


    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using TCX.Configuration;
    using System.Threading;
    
    namespace _3CXV15
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.BackgroundColor = ConsoleColor.DarkBlue;
                try
                {
                    PhoneSystem ps = PhoneSystem.Root;
    
                    Console.WriteLine("Extensions");
                    System.Console.WriteLine("Parameters:");
                    foreach (Parameter p in ps.GetParameters())
                    {
                        System.Console.WriteLine("\t" + p.ToString());
                    }
                    System.Console.WriteLine("Codecs:");
                    foreach (Codec c in ps.GetCodecs())
                    {
                        System.Console.WriteLine("\t" + c.ToString());
                    }
                    System.Console.WriteLine("Conditions:");
                    foreach (RuleCondition rc in ps.GetRuleConditions())
                    {
                        System.Console.WriteLine("\t" + rc.ToString());
                    }
                    System.Console.WriteLine("RuleHours:");
                    foreach (RuleHours rh in ps.GetRuleHourTypes())
                    {
                        System.Console.WriteLine("\t" + rh.ToString());
                    }
                    System.Console.WriteLine("RuleCalltype:");
                    foreach (RuleCallType rct in ps.GetRuleCallTypes())
                    {
                        System.Console.WriteLine("\t" + rct.ToString());
                    }
                    foreach (Tenant t in ps.GetTenants())
                    {
                        System.Console.WriteLine(t.ToString());
                        System.Console.WriteLine("\tOfficeHours:");
                        foreach (HoursRange hr in t.OfficeHoursRanges)
                        {
                            System.Console.WriteLine("\t\t" + hr);
                        }
                        System.Console.WriteLine("\tExtensions:");
                        foreach (Extension e in t.GetExtensions())
                        {
                            System.Console.WriteLine("\t\t" + e);
                            System.Console.WriteLine("\t\t\tProperties:");
                            foreach (DNProperty d in e.GetProperties())
                            {
                                System.Console.WriteLine("\t\t\t\t" + d);
                            }
                            System.Console.WriteLine("\t\t\tForwarding:");
                            foreach (ExtensionRule er in e.ForwardingRules)
                            {
                                System.Console.WriteLine("\t\t\t\t" + er);
                            }
                        }
                        foreach (IVR ivr in t.GetIVRs())
                        {
                            System.Console.WriteLine("\t\t" + ivr.Name);
                            System.Console.WriteLine("\t\t\t" + ivr.Number);
                            System.Console.WriteLine("\t\t\t" + ivr.PromptFilename);
                            System.Console.WriteLine("\t\t\t" + ivr.Timeout);
                            System.Console.WriteLine("\t\t\t" + ivr.TimeoutForwardType.ToString());
                            DN dn = ivr.TimeoutForwardDN;
                            if (dn != null)
                                System.Console.WriteLine("\t\t\t" + dn.ToString());
                            else
                                System.Console.WriteLine("\t\t\t" + "not specified");
                        }
                    }
                }
    
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("ERROR: ");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write(e.ToString());
                }
    
                Console.Write("Press enter to finish!");
                Console.ReadLine();
                
            }
        }
    }
    

    What am I doing wrong here?
     
  14. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,614
    Likes Received:
    126
    You might need to wait until PhoneSystem.Root.Connected returns true, so you're sure it's connected to the Phone System.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. Apereira

    Joined:
    Jul 23, 2016
    Messages:
    12
    Likes Received:
    0
    thanks for your reply.

    Do you mean that I need to first have a function to connect to the phone system?
     
  16. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,614
    Likes Received:
    126
    Yes, you usually want to do something like this to wait up to 1 minute for the connection:

    Code:
            bool configSrvConn = false;
            int checkCount = 0;
            do
            {
              try
              {
                configSrvConn = PhoneSystem.Root.Connected;
              }
              catch (Exception exc)
              {
                Log.Info("Configuration server not connected. Waiting 10 seconds to retry: " + exc.Message);
                Thread.Sleep(10000);
                checkCount++;
              }
            } while (!configSrvConn && checkCount < 6);
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. Apereira

    Joined:
    Jul 23, 2016
    Messages:
    12
    Likes Received:
    0
    Code:
    configSrvConn = PhoneSystem.Root.Connected;
    returns me the value True, so I assume it is connected.

    Although this it is not returning any value.

    (sorry for been so difficult)
     
  18. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,614
    Likes Received:
    126
    Are you setting the ApplicationName property? It's very important, otherwise the server will reject the connection. You need to set it to a unique name, as follows:

    Code:
                    var a = new Random(Environment.TickCount);
                    PhoneSystem.ApplicationName = "TestApi" + a.Next().ToString();
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. Apereira

    Joined:
    Jul 23, 2016
    Messages:
    12
    Likes Received:
    0
    Still not retrieving any info.

    Code I have on this function.

    Code:
            static void DisplayAllInfo()
            {
    
                bool configSrvConn = false;
                int checkCount = 0;
                var a = new Random(Environment.TickCount);
    
                PhoneSystem.ApplicationName = "TestApi" + a.Next().ToString();
    
    
    
                Console.WriteLine(PhoneSystem.ApplicationName);
                do
                {
                    try
                    {
                        configSrvConn = PhoneSystem.Root.Connected;
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine("Configuration server not connected. Waiting 10 seconds to retry: " + exc.Message);
                        Thread.Sleep(10000);
                        checkCount++;
                    }
                } while (!configSrvConn && checkCount < 6);
    
    
                Console.WriteLine("Connected to PBX: " + configSrvConn.ToString());
    
    
                // 
    
                Console.BackgroundColor = ConsoleColor.DarkBlue;
                try
                {
                    PhoneSystem ps = PhoneSystem.Root;
    
                    Console.WriteLine("Parameters:");
                    foreach (Parameter p in ps.GetParameters())
                    {
                        Console.WriteLine("\t" + p.ToString());
                    }
                    Console.WriteLine("Codecs:");
                    foreach (Codec c in ps.GetCodecs())
                    {
                        Console.WriteLine("\t" + c.ToString());
                    }
                    Console.WriteLine("Conditions:");
                    foreach (RuleCondition rc in ps.GetRuleConditions())
                    {
                        Console.WriteLine("\t" + rc.ToString());
                    }
                    Console.WriteLine("RuleHours:");
                    foreach (RuleHours rh in ps.GetRuleHourTypes())
                    {
                        Console.WriteLine("\t" + rh.ToString());
                    }
                    Console.WriteLine("RuleCalltype:");
                    foreach (RuleCallType rct in ps.GetRuleCallTypes())
                    {
                        Console.WriteLine("\t" + rct.ToString());
                    }
                    foreach (Tenant t in ps.GetTenants())
                    {
                        Console.WriteLine(t.ToString());
                        Console.WriteLine("\tOfficeHours:");
                        foreach (HoursRange hr in t.OfficeHoursRanges)
                        {
                            Console.WriteLine("\t\t" + hr);
                        }
                        Console.WriteLine("\tExtensions:");
                        foreach (Extension e in t.GetExtensions())
                        {
                            Console.WriteLine("\t\t" + e);
                            Console.WriteLine("\t\t\tProperties:");
                            foreach (DNProperty d in e.GetProperties())
                            {
                                Console.WriteLine("\t\t\t\t" + d);
                            }
                            Console.WriteLine("\t\t\tForwarding:");
                            foreach (ExtensionRule er in e.ForwardingRules)
                            {
                                Console.WriteLine("\t\t\t\t" + er);
                            }
                        }
                        foreach (IVR ivr in t.GetIVRs())
                        {
                            Console.WriteLine("\t\t" + ivr.Name);
                            Console.WriteLine("\t\t\t" + ivr.Number);
                            Console.WriteLine("\t\t\t" + ivr.PromptFilename);
                            Console.WriteLine("\t\t\t" + ivr.Timeout);
                            Console.WriteLine("\t\t\t" + ivr.TimeoutForwardType.ToString());
                            DN dn = ivr.TimeoutForwardDN;
                            if (dn != null)
                                Console.WriteLine("\t\t\t" + dn.ToString());
                            else
                                Console.WriteLine("\t\t\t" + "not specified");
                        }
                    }
                }
    
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("ERROR: ");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write(e.ToString());
                }
    
                Console.Write("Press enter to Continue!");
                Console.ReadLine();
            }
    
     
  20. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,614
    Likes Received:
    126
    Hi there,

    We've published an updated samples package for v15 which works fine. Please download it again and give it a try.

    Kind regards.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Thread Status:
Not open for further replies.