locked
Specified Cast is invalid RRS feed

  • Question

  • I am using Silverlight 4.0 with crm 2011 sdk.

    when i build the application it gives me error. (Specified cast is not valid)

    i dont know what is the cast of Guid. customerid is guid type lookup.

    the code is:

                                sb.AppendLine("Account Name = " + entity.GetAttributeValue<string>("name"));


                        string customerId = entity.GetAttributeValue<string>("customerid"); // The problem is here

                        Guid customerGuid = new Guid(customerId);
                        sb.AppendLine(customerGuid.ToString());
                        string logicalName = "Account";
                        string address;
                        if (logicalName == "Account")
                        {
                            address = getAddressOf(customerGuid);
                        }
                        else
                        {
                            address = getAddressOf(customerGuid);
                            //address = getAddressOfCustomer(customerGuid);
                        }
                                         
                       
                           
                            ManualResetEvent e = new ManualResetEvent(false);
                            System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { onLoad(address); e.Set(); });
                            e.WaitOne();

    Monday, September 12, 2011 7:58 AM

Answers

All replies

  • Hi,

    Use it like this:

     

    EntityReference customerId = entity.GetAttributeValue<EntityReference>("customerid"); 
    

     


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Monday, September 12, 2011 8:25 AM
  • Thanks for the reply Jahanzed Javeed.

     

    its really helpful but than how can i get the address of the customerId.

    Monday, September 12, 2011 8:37 AM
  • Hi,

    If You want to pass the CustomerId (Guid) value into the customerGuid then use the following code (i assume that you already have written a function for getting customer address details):

     

    EntityReference customerId = entity.GetAttributeValue<EntityReference>("customerid"); 

     

    Guid customerGuid = customerId.Id;


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".

    Monday, September 12, 2011 8:44 AM