[CLOSED] TargetException: Object does not match target type - error with store

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] TargetException: Object does not match target type - error with store

    On loading my view, which contains the following Store, I get an error:

    "TargetException: Object does not match target type"

    <ext:Store ID="AddressesStore" runat="server" AutoLoad="true" AutoDataBind="true" Json="true">
                    <BaseParams>
                        <ext:Parameter Name="Id" Value="IdHidden.getValue()" Mode="Raw"/>
                    </BaseParams>
                    <UpdateProxy>
                        <ext:HttpWriteProxy Url="/Client/SaveAddresses/" Timeout="10000"/>
                    </UpdateProxy>
                    <Proxy>
                        <ext:HttpProxy Method="GET" Url="/Client/GetAddresses/" Json="true"/>
                    </Proxy>
                    <Reader>
                        <ext:JsonReader>
                            <Fields>
                                <ext:RecordField Name="Id" Type="Int" />
                                <ext:RecordField Name="AccountId" Type="Int" />
                                <ext:RecordField Name="Address1" AllowBlank="false"/>
                                <ext:RecordField Name="Address2" />
                                <ext:RecordField Name="Address3" />
                                <ext:RecordField Name="Address4" />
                                <ext:RecordField Name="Address5" />
                                <ext:RecordField Name="Postcode" />
                                <ext:RecordField Name="Active" Type="Boolean" DefaultValue="true"  />
                           </Fields>
                        </ext:JsonReader>
                    </Reader>
                    <Listeners>
                        <Load Handler="addDefaultFieldToAddressStore();" />       
                    </Listeners>
                </ext:Store>
    My Controller action is returning an appropriate AjaxStoreResult:

    public AjaxStoreResult GetClientAddresses(string Id) {
                AccountRepository accRepo = new AccountRepository();
                IEnumerable<ClientAddress> masterAccountAddresses = accRepo.GetClientAddresses(Int64.Parse(Id));
                AjaxStoreResult addresses = new AjaxStoreResult(masterAccountAddresses.ToList());
                return addresses;
            }
    Is there a erroneous or missing setting in my View/Store causing the error?

    thanks
    Last edited by Daniil; May 17, 2011 at 11:05 AM. Reason: [CLOSED]
  2. #2
    Hi,

    It is reflection issue, i guess that problem in the serializing of ClientAddress class.
    Please provide test sample which we can run locally
  3. #3
    Quote Originally Posted by Vladimir View Post
    Hi,

    It is reflection issue, i guess that problem in the serializing of ClientAddress class.
    Please provide test sample which we can run locally
    Hi
    This is part of a more complex page. The data is via a MySql database and the main part of the page gets its data via a ViewModel. It would be pretty impossible to provide a small, working local example.

    In my Controller I can see what appears to be a perfectly valid AjaxStoreResult being returned to the view and in a previous version of the View the Store was populated fine via the Data Model. The problem only arose when the httpproxy for the store was introduced - we had to update that store/grid via ajax.

    thaks
  4. #4
    Hi,

    Can you provide definition of ClientAddress class?
  5. #5
    Quote Originally Posted by Vladimir View Post
    Hi,

    Can you provide definition of ClientAddress class?
    Our Model/Objects are auto generated from our database tables in Visual Studio. The ClientAddress class consists of:

    Id - Int64 - the Identifier
    MasterAccountId - Int
    Address1 - String
    Address2 - String
    Address3 - String
    Address4 - String
    Address5 - String
    Postcode - String
    Active - Boolean
  6. #6
    Hi,

    Are there any other properties (for example, properties with references on another entity)?
    Unfortunately, I have no idea whats wrong without test sample, are you able to create list of ClientAddress with temp data (instead of DB data retrieving)?
  7. #7
    Quote Originally Posted by Vladimir View Post
    Hi,

    Are there any other properties (for example, properties with references on another entity)?
    Unfortunately, I have no idea whats wrong without test sample, are you able to create list of ClientAddress with temp data (instead of DB data retrieving)?
    Is is a pretty standard Business Object with MasterAccountId referencing the Id of another standard Business Class, MasterAccount.

    The problem seems to have arisen when I mixed httpproxy and basic Forms/strongly typed view. To recrerate this I think I would have to recreate the ViewModel etc. I'm not sure how easy this would be.

    Unfortunately, I appear to be encountering one problem after another.

    regards
  8. #8
    Hi,

    Can you provide full stack of the exception?
    I believe that your business object service properties which cannot be serialized
    Can you convert it like in the following sample?
    var query = from c in masterAccountAddresses select new {Id = c.Id, AccountId = c.AccountId, ...};
    return new AjaxStoreResult(query);
  9. #9
    Quote Originally Posted by Vladimir View Post
    Hi,

    Can you provide full stack of the exception?
    I believe that your business object service properties which cannot be serialized
    Can you convert it like in the following sample?
    var query = from c in masterAccountAddresses select new {Id = c.Id, AccountId = c.AccountId, ...};
    return new AjaxStoreResult(query);
    Hi
    Running the following in my Controller as the httpproxy:

    var query = from c in theMasterAccountAddresses select new {Id = c.Id, MasterAccountId = c.MasterAccountId,
    Address1 = c.Address1, Address2 = c.Address2, Address3 = c.Address3, Address4 = c.Address4, Address5 = c.Address5,
    Postcode = c.Postcode, Active = c.Active};
    return new AjaxStoreResult(query);

    I seem to get the data I expect, however, I don't now get an exception. My store, though, does not get populated, even though I've got:

    <ext:Store ID="masterAccountAddressesStore" runat="server" Json="true" AutoLoad="true" AutoDataBind="true" >

    thanks
  10. #10
    Hi,

    <ext:HttpProxy Method="GET" Url="/Client/GetAddresses/" Json="true"/>
    Please remove Json=true and retest
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: Jul 01, 2014, 1:45 PM
  2. Set target window for Notification object
    By RPIRES in forum 1.x Help
    Replies: 7
    Last Post: Jun 17, 2010, 8:45 PM
  3. ext:Store shows error message "Object expected"
    By stephan1985 in forum 1.x Help
    Replies: 0
    Last Post: Jan 09, 2010, 8:38 AM
  4. Replies: 6
    Last Post: Aug 28, 2009, 12:19 PM
  5. Replies: 2
    Last Post: Feb 05, 2009, 11:02 AM

Posting Permissions