locked
Unable to cast object of type 'System.String[]' to type 'System.String' RRS feed

  • Question

  • Hi All,

    I am unable to resolve this error from my code.

    using System;
    using System.Collections.Generic;
    using Microsoft.Win32;
    
    // Microsoft Dynamics CRM namespaces
    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.SdkTypeProxy;
    using Microsoft.Crm.SdkTypeProxy.Metadata;
    using Microsoft.Crm.Sdk.Query;
    using System.Web.Services.Protocols;
    
    namespace FeePlugin
    {
      public class FeePlugin : IPlugin
      {
        #region Variable Declaration
        public ICrmService service;
        public Guid FeeGuid = Guid.Empty;
        #endregion
        // Related SDK topic: Writing a Plug-in
        public void Execute(IPluginExecutionContext context)
        {
          try
          {
            service = context.CreateCrmService(true);
            DynamicEntity entity = null;
    
            // Check if the InputParameters property bag contains a target
            // of the current operation and that target is of type DynamicEntity.
            if (context.InputParameters.Properties.Contains(ParameterName.Target) &&
              context.InputParameters.Properties[ParameterName.Target] is DynamicEntity)
            {
              // Obtain the target business entity from the input parmameters.
              entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
              if (entity.Name == "new_fee")
              {
                if (context.MessageName == MessageName.Create)
                {
                  if (context.OutputParameters.Properties.Contains("id"))
                  {
                    FeeGuid = new Guid(context.OutputParameters.Properties["id"].ToString());
                    AssignPaymentTrackID();
                  }
                }
                if (context.MessageName == MessageName.Update)
                {
                  DynamicEntity PostImage = (DynamicEntity)context.PostEntityImages["PostImage"];
                  FeeGuid = ((Lookup)PostImage.Properties["new_feesid"]).Value;
                  if (!(PostImage.Properties.Contains("new_reverseflag")))
                  {
                    Retriveissue(FeeGuid);
     
                  }
                  
                }
              }
    
            }
            else
            {
              return;
            }
    
    
          }
          catch (SoapException ex)
          {
            throw new InvalidPluginExecutionException(ex.Detail.InnerText);
          }
    
        }
    
        private void Retriveissue(Guid FeeGuid)
        {
          try
          {
            ColumnSet cols = new ColumnSet();
    
            // Set the properties of the column set.
            cols.Attributes.Add(new string[] { "new_issue_id"});
    
            // Create the ConditionExpression.
            ConditionExpression condition = new ConditionExpression();
    
            // Set the condition for the retrieval to be when the city in the account's address is Sammamish.
            condition.AttributeName = "new_issueid";
            condition.Operator = ConditionOperator.Like;
            condition.Values = new object[] { FeeGuid };
    
            // Create the FilterExpression.
            FilterExpression filter = new FilterExpression();
    
            // Set the properties of the filter.
            filter.FilterOperator = LogicalOperator.And;
            filter.Conditions.Add(new ConditionExpression[] { condition });
    
            // Create the QueryExpression object.
            QueryExpression query = new QueryExpression();
    
            // Set the properties of the QueryExpression object.
            query.EntityName = "new_issue";
            query.ColumnSet = cols;
            query.Criteria = filter;
    
            // Create the request object.
            RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
    
            // Set the properties of the request object.
            retrieve.Query = query;
    
            // Execute the request.
            RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
    
    
    
          }
          catch (SoapException ex)
          {
            throw new InvalidPluginExecutionException(ex.Detail.InnerText);
          }
    
        }
    
        private void AssignPaymentTrackID()
        {
          throw new Exception("The method or operation is not implemented.");
        }
      }
    }
    
    
    This error comes in inner exception for the code

    RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
    
    Regards,
    Shivam
    Thursday, December 23, 2010 11:45 PM

Answers

All replies

  • try to change your code as below for these lines

    ColumnSet cols = new ColumnSet(new string[] { "new_issue_id"});

     
     filter.Conditions.AddRange(new ConditionExpression[] { condition });

    also add

    retrieve.ReturnDynamicEntities = true;


    Mahain : My Dynamics CRM Blog
    Friday, December 24, 2010 2:00 AM
    Moderator
  • Hi Shivam,

     

    Change here:

    cols.Attributes.Add(new string[] { "new_issue_id"});
    

    to

    cols.Attributes.Add("new_issue_id");

     

    Regard,

     


    Ricardo Alves
    www.ricardoalves.me
    Friday, December 24, 2010 2:47 AM