By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

PInvokeStackImbalance during insert - MySqlDriverCS 4.0 for .Net 2 C# V8 VS2005

P: 1

I'm having trouble tracking down a PInvoke error in the MySqlDriverCS lib, which is detected even in the author's samples converted to VS v8 .Net 2.0.

The calling maze is provided, but the bottom two are really the (offending) and external unsafe (offended), being called.

I just cannot see where it's off track to cause the error. I did notice the MySql lib appears to be ver 4.nn of MySql's tree, but still the functions appear that they should be compatible and that's apparently where the MySqlDriverCS authors found MySql at the time of their most recent revision. ?? The authors did not reply to email.

Any suggestions are truly appreciated.

C# on 2005VS express edition
MySqlDriverCS 4.0 .Net 2 compatible
WinXP Home, current, on Intel Celron 2.7 Ghz.
MySql 5.0.22-community-nt on TCP/IP
Client Version 5.1.11

PInvokeStackImbalance was detected
Message: A call to PInvoke function 'MySQLDriverCS!MySQLDriverCS.CPrototypes::mysql_re al_escape_string' has unbalanced the stack.

Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

Originating call:
Expand|Select|Wrap|Line Numbers
  1. new MySQLInsertCommand(conn,
  2. new object[,] {{"SettingID",SettingID},{"SettingValue",Value}},
  3. "mysqldrivercs_test"
  4. );
Calls to: (MySQLInsertCommand.cs)
Expand|Select|Wrap|Line Numbers
  1. public MySQLInsertCommand(
  2. MySQLConnection conn, 
  3. object[,] FieldsAndValues, 
  4. string Table)
Which contains an internal call to:
Expand|Select|Wrap|Line Numbers
  1. {
  2. query += " "+MySQLUtils.Escape(Value.ToString(), conn)+" ";
  3. }
In turn calling: MySQLUtils.cs:
Expand|Select|Wrap|Line Numbers
  1. unsafe internal static string Escape(string str,
  2.  MySQLConnection conn) 
  3. {
  4. byte[] bytes = conn.CharacterEncoding.GetBytes(str);
  5. StringBuilder to = new StringBuilder(bytes.Length*2 +1);
  6. StringBuilder result = new StringBuilder(bytes.Length*2 + 1);
  7. result.Append('\'');
  9. (immediately falling to:)
  11. CPrototypes.mysql_real_escape_string(
  12. conn.Handle, to, str, (ulong)bytes.Length);
  13. result.Append(to);
  14. result.Append('\'');
  15. return result.ToString() ;
Causing "Offending call" in CPrototypes.cs:
Expand|Select|Wrap|Line Numbers
  1. [ DllImport( "libmySQL.dll",
  2. EntryPoint="mysql_real_escape_string" )]
  3. unsafe public static extern ulong mysql_real_escape_string(
  4.  void *mysql,
  5.  System.Text.StringBuilder to,
  6.  string from,
  7.  ulong length);
Compared to:

Target unmanaged signature in libmySql:
Expand|Select|Wrap|Line Numbers
  1. mysql_real_escape_string()
  2.  unsigned long mysql_real_escape_string(
  3. MYSQL *mysql,
  4.  char *to,
  5.  const char *from,
  6.  unsigned long length)
Thank you for any suggestions,

Apr 21 '07 #1
Share this Question
Share on Google+
1 Reply

P: 1
I had the same problem. After 3 hours i found the solution, ehhh.

Try to use MySQLDriverCS.dll
from C:\Program iles\MySQLDriverCS\source\samples\InsertOrUpdate\b in\Release directory instead of
C:\Program Files\MySQLDriverCS\dll\MySQLDriverCS.dll

The first one is older(size is different too) and i don't know why the newer version doesn't work with insertcommand....

May 12 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.