Error using OMsamples

Status
Not open for further replies.

Apereira

Silver Partner
Advanced Certified
Joined
Jul 23, 2016
Messages
23
Reaction score
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.

OMSamples.exe /remove_extension 500
Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at OMSamples.SampleStarter.StartSample(String[] args) in C:\Users\AndréPereira\OneDrive\Desktop\3CXAPI\v15\CallControl\OMSamples\SampleStarter.cs:line 101

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

Can someone please help?
 
Adding more information.

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

An unhandled exception of type 'System.BadImageFormatException' occurred in 3cxpscomcpp2.dll

Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)


On line

Code:
PhoneSystem ps = PhoneSystem.Root;
 
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.
 
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

An unhandled exception of type 'System.DllNotFoundException' occurred in 3cxpscomcpp2.dll

Additional information: Unable to load DLL 'tcxpscom_native': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
 
That DLL is in folder "C:\Program Files\3CX Phone System\Bin". Copy it to your project output folder.
 
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?
 
In your reference set CopyLocal to true, and that will copy the DLL to your output folder.
 
It was already set to true.

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

Error:

System.DllNotFoundException: Unable to load DLL 'tcxpscom_native': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at TCX.Configuration.PhoneSystem.RegisterListener(MyPFN_UPDATE_LISTENER f)
at TCX.Configuration.PhoneSystem.get_Root()
at _3CXV15.Program.Main(String[] args) in C:\Users\APereira\OneDrive\documents\visual studio 2015\Projects\3CXV15\3CXV15\Program.cs:line 17
 
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".
 
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.
 
After a few attempts still having the same issue, it states that it can't load the other DLL.
 
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.
 
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?
 
You might need to wait until PhoneSystem.Root.Connected returns true, so you're sure it's connected to the Phone System.
 
thanks for your reply.

Do you mean that I need to first have a function to connect to the phone system?
 
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);
 
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)
 
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();
 
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();
        }
 
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.
 
Status
Not open for further replies.

Forum statistics

Threads
112,322
Messages
591,889
Members
165,470
Latest member
Robert Lee