longtext being read in as byte[]

longtext being read in as byte[]

Postby njb » Fri 10 Nov 2017 19:06

I am not sure what the issue is here, but we are having a problem with the dotConnect for MySQL connector. Apparently it is reading a longtext column as a byte[] instead of a string. We use LLBL on top of the connector for our entity generation. Here is the pertinent code which fails:
Code: Select all
      public virtual System.String PossibleResponses
         get { return (System.String)GetValue((int)QuestionsFieldIndex.PossibleResponses, true); }
         set   { SetValue((int)QuestionsFieldIndex.PossibleResponses, value); }

The PossibleResponses column is a LONGTEXT containing some JSON.

The GetValue call rerturns a byte[] instead of a string and when the cast happens it gives the following exception:
System.InvalidCastException: 'Unable to cast object of type 'System.Byte[]' to type 'System.String'."

We are using dotConnect 8.10 and will be trying to downgrade to 8.98 here shortly.

Thanks for any help that can be provided.
Posts: 4
Joined: Sat 25 Feb 2017 01:12

Re: longtext being read in as byte[]

Postby Pinturiccio » Tue 14 Nov 2017 14:19

We could not reproduce the issue. We have the following table:
Code: Select all
CREATE TABLE longtable (
  val longtext DEFAULT NULL,

INSERT INTO longtable(val) VALUES('[{"id":10529970189,"variant_id":20236601729,"title":"Test product","quantity":1,"price":"100.00","grams":0,"sku":"10TEST","variant_title":null,"vendor":"2332947294cf4dd08212","fulfillment_service":"manual","product_id":6440057793,"requires_shipping":true,"taxable":true,"gift_card":false,"name":"Test product","variant_inventory_management":null,"properties":[],"product_exists":true,"fulfillable_quantity":0,"total_discount":"0.00","fulfillment_status":"fulfilled","tax_lines":[]}]');

and the following code:
Code: Select all
MySqlConnection conn = new MySqlConnection("your connection string");

MySqlCommand comm = new MySqlCommand("select val from longtable", conn);
var reader = comm.ExecuteReader();

Please tell us how we should change this code for reproducing the issue. Please also tell us your MySQL server version.
Devart Team
Posts: 2024
Joined: Wed 02 Nov 2011 09:44

Return to dotConnect for MySQL