• V20: 3CX Re-engineered. Get V20 for increased security, better call management, a new admin console and Windows softphone. Learn More.
Status
Not open for further replies.

BrechtD

Joined
Apr 8, 2018
Messages
14
Reaction score
0
Hello everyone

I am creating an external script to let my call flow designer application connect to a MySql database.
I had to add some dependencies of which MySql.Data.dll is one of them. I added this dll and it's dependencies to the /usr/lib/3cxpbx folder (my 3CX server is running on a Debian machine). But every time my script is running, I see an error in my QueueManager logs telling me that this DLL could not be found, eventhough I added him to that folder. I even tried to restart the server without any result.

This is the error I get:

Code:
18/04/27 09:12:15.861|100030| Err|10|0018|: PlugIn[MySQLConnectionTest - Callflow - MainFlow - CallID WIZJRYQFAUQE] ERROR: Error executing last component: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'MySql.Data, Version=6.10.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'. The system cannot find the file specified.

   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at MySQLConnectionTest.ExternalCodeExecutionComponent.executeStart(QMExtendAPI iface, String id)
   at MySQLConnectionTest.ExternalCodeExecutionComponent.Start(QMExtendAPI iface, CallQueue callQueue, QueueCall queueCall, ActiveConnection activeConnection, TimerManager timerManager, Dictionary`2 variableMap, TempWavFileManager tempWavFileManager, PromptQueue promptQueue)
   at MySQLConnectionTest.SequenceContainerComponent.Start(QMExtendAPI iface, CallQueue callQueue, QueueCall queueCall, ActiveConnection activeConnection, TimerManager timerManager, Dictionary`2 variableMap, TempWavFileManager tempWavFileManager, PromptQueue promptQueue)
   at MySQLConnectionTest.ConditionalComponent.Start(QMExtendAPI iface, CallQueue callQueue, QueueCall queueCall, ActiveConnection activeConnection, TimerManager timerManager, Dictionary`2 variableMap, TempWavFileManager tempWavFileManager, PromptQueue promptQueue)
   at MySQLConnectionTest.Callflow.ProcessStart()


Hopefully one of you can help me with this.


Kind regards

Brecht
 
Hello Brecht,

3CX will not load any DLL that was not installed by 3CX, even if you copy it to the binary folder. So in order to do this, you would need to use a C# script to programmatically load the assembly from the path where it is, and then you should be able to use it.

Kind regards.
 
Hello Brecht,

3CX will not load any DLL that was not installed by 3CX, even if you copy it to the binary folder. So in order to do this, you would need to use a C# script to programmatically load the assembly from the path where it is, and then you should be able to use it.

Kind regards.

So I found a way to call this DLL within my C# script. First I had to install it using Mono on Linux.
See: https://github.com/ikkentim/SampSharp/wiki/installing-mysql.data.dll-on-linux
But My program still says that it cannot find the DLL. I have used the correct DLL string, even checked to be sure and it should be correct. So I'm quite confused right now why this still won't work :/

Here is my code of my external C# script:
Code:
using System;
using System.Reflection;

namespace MysqlConnection
{
class MyConnection
{

public static bool Con()
{
String ConnectionString = "server=10.10.5.244;user id=root;password=root;persistsecurityinfo=True;port=3306;database=test";
String[] vars = new string[1];
vars[0] = ConnectionString;
//C:\Program Files\3CX Call Flow Designer\CompilerDependencies\MySql.Data.dll
//Assembly assembly = Assembly.LoadFile(@"/usr/lib/3cxpbx/MySql.Data.dll");
string longName = "MySql.Data, Version=6.10.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d";
AssemblyName name = new AssemblyName(longName);
Assembly assembly = Assembly.Load(name);
//Assembly.LoadFile not found
//Assembly.LoadFrom not found
Type type = assembly.GetType("MySql.Data.MySqlClient.MySqlConnection");

MethodInfo myMethod = type.GetMethod("Open");
// Create an instance.
object obj = Activator.CreateInstance(type, vars);
// Execute the method.
bool failed = false;
try
{
myMethod.Invoke(obj, null);
}
catch (Exception e)
{
failed = true;
}

return failed;

}
}
}

Here you have the exception that it throws in my QueueManager.log file:
Code:
18/05/02 10:49:44.088|100030| Err|10|0020|: PlugIn[MySQLConnectionTest - Callflow - MainFlow - CallID UETBASHAPPWM] ERROR: Error executing last component: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'MySql.Data, Version=6.10.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'. The system cannot find the file specified.

   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks, IntPtr ptrLoadContextBinder)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, IntPtr ptrLoadContextBinder)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
   at MysqlConnection.MyConnection.Con()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at MySQLConnectionTest.ExternalCodeExecutionComponent.executeStart(QMExtendAPI iface, String id)
   at MySQLConnectionTest.ExternalCodeExecutionComponent.Start(QMExtendAPI iface, CallQueue callQueue, QueueCall queueCall, ActiveConnection activeConnection, TimerManager timerManager, Dictionary`2 variableMap, TempWavFileManager tempWavFileManager, PromptQueue promptQueue)
   at MySQLConnectionTest.SequenceContainerComponent.Start(QMExtendAPI iface, CallQueue callQueue, QueueCall queueCall, ActiveConnection activeConnection, TimerManager timerManager, Dictionary`2 variableMap, TempWavFileManager tempWavFileManager, PromptQueue promptQueue)
   at MySQLConnectionTest.ConditionalComponent.Start(QMExtendAPI iface, CallQueue callQueue, QueueCall queueCall, ActiveConnection activeConnection, TimerManager timerManager, Dictionary`2 variableMap, TempWavFileManager tempWavFileManager, PromptQueue promptQueue)
   at MySQLConnectionTest.Callflow.ProcessStart()

Any clue what else could be wrong?

Kind regards

Brecht
 
Last edited:
Try using the following to load the assembly:
System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(path)
 
Try using the following to load the assembly:
System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(path)

Hello Ernesto

I did that and it seems to work, but now I am having a strange error which says :

Could not load file or assembly 'System.Security.Permissions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Any idea about this,

Kind regards
 
Maybe that's a depencency of the MySQL library. You can try to load that assembly as well.
 
Maybe that's a depencency of the MySQL library. You can try to load that assembly as well.

Hey Ernesto

I did and this seemed to work until the program said that the class system.data.common.dbdatapermission
could not be found in the assembly or file system.data.common eventhough it is there. I even tried to load that assembly as well but without any result.

Kind regards
 
Probably a dependent DLL is missing. Try loading all the dependencies assemblies.
 
Status
Not open for further replies.
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.