CallControlAPI - issues with tcxpscom_native.dll

Status
Not open for further replies.

HarryLAF

Forum User
Joined
Sep 11, 2018
Messages
2
Reaction score
0
I am working on an a service using the CallControlAPI under .NET Core 2.0 and a Fresh install of latest 3CX on Windows.

The following code when run with the 3cxpscomcpp2.dll included as a reference with copy local on errors on run with the following message:
System.DllNotFoundException: 'Unable to load DLL 'tcxpscom_native': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'

Code:
    class Program
    {
        private static string _instanceBinPath;

        private static PhoneSystem Bootstrap(string filePath)
        {
            {
                var a = new Random(Environment.TickCount);
                PhoneSystem.ApplicationName = "LAFCallControl"; //any name
                PhoneSystem.ApplicationName = PhoneSystem.ApplicationName + a.Next().ToString();
            }
            var portString = Utilities.GetKeyValue("ConfService", "ConfPort", filePath);
            PhoneSystem.CfgServerHost = "127.0.0.1";
            if (!string.IsNullOrEmpty(portString))
            {
                var port = int.Parse(portString.Trim());
                PhoneSystem.CfgServerPort = port;
            }

            var user = Utilities.GetKeyValue("ConfService", "confUser", filePath);
            if (!string.IsNullOrEmpty(user)) PhoneSystem.CfgServerUser = user;
            var pass = Utilities.GetKeyValue("ConfService", "confPass", filePath);
            if (!string.IsNullOrEmpty(pass)) PhoneSystem.CfgServerPassword = pass;

            var dns = PhoneSystem.Root.GetDN(); //Access PhoneSystem.Root to initialize ObjectModel
            if (dns != null)
            {
                Console.WriteLine("Setup Complete");
                return PhoneSystem.Root;
            }

            throw new Exception("Unable to Bootstrap PhoneSystem");
        }

        private static void Main()
        {
            PhoneSystem phoneSystem;

            try
            {
                // load 3cx configs
                var filePath = @"C:\Program Files\3CX Phone System\Instance1\Bin\3CXPhoneSystem.ini";
                if (!File.Exists(filePath)) throw new Exception("Cannot find 3CXPhoneSystem.ini");
                Console.WriteLine("Config Found at " + filePath);

                // load 3cx dll
                _instanceBinPath = Path.Combine(Utilities.GetKeyValue("General", "AppPath", filePath), "Bin");
                foreach (string dll in Directory.GetFiles(@"C:\Program Files\3CX Phone System\Instance1\Bin", "*.dll", SearchOption.TopDirectoryOnly))
                {
                    try
                    {
                        Assembly loadedAssembly = Assembly.LoadFile(dll);
                    }
                    catch (FileLoadException loadEx)
                    {
                        Console.WriteLine(dll + " failed load, " + loadEx.Message);
                    } // The Assembly has already been loaded.
                    catch (BadImageFormatException imgEx)
                    {
                        Console.WriteLine(dll  + " failed load, " + imgEx.Message);
                    } // If a BadImageFormatException exception is thrown, the file is not an assembly.
                }

                //AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

                // initialise "connection" to the phone system
                Console.WriteLine("Bootstrap");
                phoneSystem = Bootstrap(filePath);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }

            // do the things to the phone system
        }

When including the tcxpscom_native.dll as a reference in the same way as 3cxpscomcpp2.dll the same error occurs. at run time and when building the following message is displayed:
warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible. Could not load file or assembly 'tcxpscom_native.dll' or one of its dependencies. The module was expected to contain an assembly manifest.

I have read elsewhere that including sl.dll is also required however when trying this the error and build output are the same.

Does anyone have any idea what is going on?
 
Hello @HarryLAF,

In your project you just need to have a reference to 3cxpscomcpp2.dll. But, in your project output you need to copy the files sl.dll and tcxpscom_native.dll, so they're available when you run your app.

Kind regards.
 
  • Like
Reactions: HarryLAF
Thank you for the prompt reply - solved my problem
 
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
112,323
Messages
591,896
Members
165,474
Latest member
costionofrei