Bug #92765 MySQL Connector 6.10.8/EntityFrameWork 6/oData
Submitted: 12 Oct 2018 13:16 Modified: 13 Mar 17:01
Reporter: Ray Harrison Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:6.10.8 OS:Any
Assigned to: CPU Architecture:Any
Tags: EntityFrameWork 6/oData, MySQL Connector 6.10.8

[12 Oct 2018 13:16] Ray Harrison
Description:
Hi,

We have VS20117 and I have created a WebAPI Odata service  using the entityframework 6.
This is linked to a mysql database using the MYSQL connector 6.10.8.0.

All seems to work.
I can query the data using a odata URL.

http://localhost:8080/odata/product_master

This returns a json object representing the product_master data.

Within the database I have lots of linked tables to my product_master.  Such as classifications, suppliers, locations etc

Therefore if I access the below URL then all works..

http://localhost:8080/odata/product_master(1)?$expand=product_classifications

I get a json reponse showing me product 1 and all its classifications.  So all seems ok.

HOWEVER.  If I expand more than two tables... in any order / combination then I get an exception error from the 
MySQL Connecctor.

http://localhost:8080/odata/product_master(1)?$expand=product_classifications,product_loca...
 
I then get the error below.

{"error":{"code":"","message":"An error has occurred.","innererror":{"message":"Exception has been thrown by the target of an invocation.","type":"System.Reflection.TargetInvocationException","stacktrace":"   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)\r\n   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)\r\n   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetTypedValueDefault(DbDataReader reader, Int32 ordinal)\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)\r\n   at lambda_method(Closure , Shaper )\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)\r\n   at lambda_method(Closure , Shaper )\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.RowNestedResultEnumerator.MaterializeRow()\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.RowNestedResultEnumerator.MoveNext()\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.TryReadToNextElement()\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.ReadElement()\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.MoveNext()\r\n   at Microsoft.AspNet.OData.EnableQueryAttribute.SingleOrDefault(IQueryable queryable, IWebApiActionDescriptor actionDescriptor)\r\n   at Microsoft.AspNet.OData.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, Func`2 modelFunction, IWebApiRequestMessage request, Func`2 createQueryOptionFunction)\r\n   at Microsoft.AspNet.OData.EnableQueryAttribute.OnActionExecuted(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, IWebApiRequestMessage request, Func`2 modelFunction, Func`2 createQueryOptionFunction, Action`1 createResponseAction, Action`3 createErrorAction)\r\n   at Microsoft.AspNet.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()","internalexception":{"message":"Specified cast is not valid.","type":"System.InvalidCastException","stacktrace":"   at MySql.Data.MySqlClient.MySqlDataReader.GetByte(Int32 i)"}}}}

I have searched all over the internet and cant find anyone whos had the same issue.

I have therefore also updated the connector to use 8.0.12.  This seems to have exactly the same issue as above and also if I try to add additional tables to my entity model the entity model wizard closes when you click next before it shows any tables.

Thanks

Ray

How to repeat:
Simply create a WebAPI OData Service, use the MySQL Connector and have a database that has say one master table with 4 linked tables as below.

http://localhost:8080/odata/product_master(1)?$expand=product_classifications,product_loca...

This should return a json string with the master data, a list of classifications, locations and suppliers link to that product.  However it crashes out.

Suggested fix:
The exception seems to be a simple cast.

Specified cast is not valid.","type":"System.InvalidCastException","stacktrace":"   at MySql.Data.MySqlClient.MySqlDataReader.GetByte(Int32 i)
[18 Oct 2018 9:47] MySQL Verification Team
Thank you for the bug report. In How to Repeat the below links doesn't works, please print here instead. Thanks.

http://localhost:8080/odata/product_master(1)?$expand=product_classifications,product_loca...
[18 Oct 2018 10:01] Ray Harrison
Miguel Solorzano - I dont understand your comment.  The URL is an example of whats 
entered into a browser to access the localhost odata.
[18 Oct 2018 10:27] MySQL Verification Team
Thank you for the feedback. Sorry I thought the link was for external data.
[30 Nov 2018 14:42] Ray Harrison
Has anyone got either a fix for this or a workaround as I cant proceed... this bug is stopping my project.

Thanks

Ray
[13 Mar 17:01] Filipe Silva
Bug closed due to not being able to reproduce. If the problem persists then please report again and provide a reproducible test case.