Unable to cast object of type 'System.Object[]' to type 'OpenAccessRuntime.DataObjects.query.Node with anonymous types

Thread is closed for posting
7 posts, 0 answers
  1. G.
    G. avatar
    6 posts
    Member since:
    Jul 2010

    Posted 06 May 2011 Link to this post

    Hi guys - I am getting the following exception when trying to use your OA ORM against Oracle (a wcf data service project)
    if I query the entire entity (all properties) without projecting the results (EntitySet.Where(w=>w.Id== "123456")  things are working fine. But if I try to project the results into an anonymous type such as EntitySet.Where(w=>w.Id== "123456").Select(w=> new {w.Name}) I get the exception below.

    Unable to cast object of type 'System.Object[]' to type 'OpenAccessRuntime.DataObjects.query.Node

    From what I am reading on your forums, there was a similar problem with previous version of OA.
    However, I am running version 2011.1.411.2 .
    Could you please advise how to go about resolving the issue? 

    G.
  2. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 09 May 2011 Link to this post

    Hi G.,

    I tried to reproduce this here but had no success. What is the column type involved? Also, you could try to leave out the anonymous type from the projection, e.g. .Select(w => w.Name) . 

    Kind regards,
    Thomas
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  3. Mike Henders
    Mike Henders avatar
    11 posts
    Member since:
    May 2006

    Posted 09 May 2011 Link to this post

    I too have just started wrapping OpenAccess with a WCF Data Service and am receiving the same error.  I can reproduce it by sending oData formatted queries through my browser.

    The object being queried looks roughly like this.  In reality it is a partial class generated by OpenAccess.  The DataServiceKey was added by me because OpenAccess doesn't generate EntityFramework types.

    [DataServiceKey("CreativeOID")]
    public class Creative {
       public string MimeType { get; set; }
       public int Height {get; set; }
       public int Width { get; set; }
       public int CreativeOID { get; set; }
       public int CreativeTypeOID { get; set; }
       public int CampaignOID { get; set; }
       public byte[] Data { get; set; }
    }

    The query http://localhost:12345/Services/MyDataService.svc/Creatives?$filter=... works correctly with a variety of different filters.  However, http://localhost:12345/Services/MyDataService.svc/Creatives?$select=CreativeOID returns:

    <?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
    <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
      <code></code>
      <message xml:lang="en-CA">An error occurred while processing this request.</message>
      <innererror>
        <message>An exception occured during the execution of '&#xD;
    Extent&lt;Alaris.CampaignManager.Models.Creative&gt;.Select(p =&gt; IIF((p == null), null, new ProjectedWrapper1() {ResourceTypeName = "Alaris.CampaignManager.Models.Creative", PropertyNameList = "CreativeOID", ProjectedProperty0 = Convert(Convert((p As Creative).CreativeOID))}))'. See InnerException for more details.&#xD;
    </message>
        <type>System.InvalidOperationException</type>
        <stacktrace>   at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid)&#xD;
       at Telerik.OpenAccess.Query.ExpressionExecution.PerformDatabaseQuery[T](Piece`1 piece, Object[] grpVals)&#xD;
       at Telerik.OpenAccess.Query.Piece`1.System.Collections.IEnumerable.GetEnumerator()&#xD;
       at System.Data.Services.Internal.ProjectedWrapper.EnumerableWrapper.System.Collections.IEnumerable.GetEnumerator()&#xD;
       at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable)&#xD;
       at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService)&#xD;
       at System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description)&#xD;
       at System.Data.Services.DataService`1.HandleRequest()</stacktrace>
        <internalexception>
          <message>Unable to cast object of type 'System.Object[]' to type 'OpenAccessRuntime.DataObjects.query.Node'.</message>
          <type>System.InvalidCastException</type>
          <stacktrace>   at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid)&#xD;
       at Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid)</stacktrace>
        </internalexception>
      </innererror>
    </error>

    I want to use the select system query option to avoid sending the data across the wire when the client doesn't want it.

    Cheers,
    Mike
  4. G.
    G. avatar
    6 posts
    Member since:
    Jul 2010

    Posted 09 May 2011 Link to this post

    Mike - This is precisely what I am experiencing as well. Maybe I confused things a bit by mentioning the anonymous class. All that does is generates a DataService query with $select list of properties that I need returned (a subset of the actual class properties). So whenever the $select keyword is used in the URI query I get the mentioned exception. 

    Thomas -  To adequately repro the issue, you'll need to create a WCF Data Service that sits on top of a DataContext created by running your  OpenAcess-> Add Domain Model Wizard (or just use the project template). Then when you issue a DataService URI query (against the service) containing the $select<list of properties to return> you should get the exception that Mike and I mentioned. 

    I am not sure if this is of any significance or not for your testing, but my Models (OA generated) are in a separate Class Library project that the Service Project references. 

    PS. Thomas - The  type of the requested property does not appear to matter - just tested it with String, DateTime and Long - same exception every time. It is at least consistently failing :) 
  5. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 10 May 2011 Link to this post

    Hi G.,

    I can reproduce this now. Looks like the DataServices create a certain kind of projection that our LINQ does not support yet; I will work on that, maybe a fix is not that difficult. 

    Regards,
    Thomas
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  6. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 20 Jun 2011 Link to this post

    Hello G.,

    this issue has been fixed in the upcoming Q2 2011 release.

    Kind regards,
    Thomas
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  7. G.
    G. avatar
    6 posts
    Member since:
    Jul 2010

    Posted 20 Jun 2011 Link to this post

    Thank you for following up Thomas, looking forward to the new release.
Back to Top