The structure must not be a value class

  • Francesco Pagano

    Hi, I am using mysqldrivercs  rel. 4.0.1 in a .Net 2.0 ASP (C#) application. If I use it in my development machine, with Visual Studio 2005 and MySQL 5 all is ok. When i try to deploy the application, I get the following problems:
    1) I cannot connect to a remote MySql server. I use the following statements:
                con.ConnectionString=("Server=" + server +";Data Source=" + nome_db + ";User ID=" + username + ";Password=" + password +";Persist Security Info=True;");

    The problem is that the username sent to my dbserver is ever concatenated with "@localhost" though I am using the ip address for "server"

    2) in another server, where there is MySql 4.1, the statements:
            public MySQLDataReader select(string sql)
                MySQLCommand cmd = new MySQLCommand(sql,con);
                MySQLDataReader dr = cmd.ExecuteReaderEx();
                return dr;

            private void carica_combo_cat()
                Database db = new Database();
                MySQLDataReader dr;
                dr ="Select nome_cat from categorie order by ID");

    fail with the following stack trace:
    [ArgumentException: The structure must not be a value class.
    Parameter name: structure]
       System.Runtime.InteropServices.Marshal.PtrToStructureHelper(IntPtr ptr, Object structure, Boolean allowValueClasses) +0
       MySQLDriverCS.MySQLDataReader..ctor(Void* result, MySQLConnection _connection, Statement _stmt, Boolean CloseConnection) +275
       MySQLDriverCS.DirectStatement.ExecuteReader(Boolean CloseConnection) +123
       MySQLDriverCS.MySQLCommand.ExecuteReader(Boolean CloseConnection) +65
       MySQLDriverCS.MySQLCommand.ExecuteReaderEx() +7 sql) in C:\Users\Roberto\Desktop\Tesi\Programma\Miles maps\WebApplication1\Database.cs:58
       WebApplication1.Ricerca.carica_combo_cat() in C:\Users\Roberto\Desktop\Tesi\Programma\Miles maps\WebApplication1\Ricerca.aspx.cs:119
       WebApplication1.Ricerca.Page_Load(Object sender, EventArgs e) in C:\Users\Roberto\Desktop\Tesi\Programma\Miles maps\WebApplication1\Ricerca.aspx.cs:35
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +47
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

    I read that the problem is in the overload version of PtrToStructureHelper used. How can I solve this problem?

    • miles6

      miles6 - 2007-11-23

      hi, I have the solution.
      You need install the driver of connector (MySQLDriverCS) in the server too.
      Only dll isn't enought.
      I had the same problem and with the installation of driver the application works fine.

    • rmccullough

      rmccullough - 2009-01-15

      There is a more correct solution, but you need to download and compile the MySQLDriverCS code yourself until it is fixed.
      In MySQLDataReader.cs, on about line 71, replace


Log in to post a comment.