Question Status

Unanswered
Chirag Kanzariya asked a question on 18 Feb 2015 5:48 AM

Hello,


I have a Synchronous plugin that runs when any opportunity create/delete/update. And in Plugin if any error comes i have made a function which insert log into database.

In table one field if EntityId, so i am writing the following code :

foreach (PropertyBagEntry entry in (IEnumerable<PropertyBagEntry>)context.InputParameters.Values)
{

        DynamicEntity entity = (DynamicEntity)entry.Value;
        foreach (Property property in (IEnumerable<Property>)entity.Properties)
        {
            if (property.GetType().Name == "KeyProperty")
            {
                str4 = ((Key)entity.Properties[property.Name]).Value.ToString();
                break;
            }
        }
}

In str4 i am getting EntityId of current process.

But it gives one exception very frequently :

Unhandled Exception: System.InvalidCastException: Unable to cast object of type
'ValueCollection[System.String,System.Object]'
to type 'System.Collections.Generic.IEnumerable`1[Microsoft.Crm.Sdk.PropertyBagEntry]'

And i have identified that the following line is giving error 

foreach (PropertyBagEntry entry in (IEnumerable<PropertyBagEntry>)context.InputParameters.Values)


Anyone have idea to convert this line in another way ?

Thanks

Reply
Mahender Pal responded on 18 Feb 2015 8:00 AM

Hello,

This code is for MS CRM 4.0, it won't work for MSCRM 2013, you need to upgrade your code according to ms crm 2011/2013 standards.

Please refere: www.resultondemand.nl/.../4c7669b6-3883-4a83-973d-0fc2cc9dd500.htm


Need help in CRM Contact US | Our Blog | Follow US | Like our Facebook Page | Our Book

Make sure to Vote as Helpful and  Mark As Answer ,if you get answer of your question.

Reply
Chirag Kanzariya responded on 18 Feb 2015 11:58 PM

Hi,

I am not able to find any related topic to this in that link.

Reply
Mahender Pal responded on 22 Feb 2015 4:59 AM

Above post will provide you information what all the points you keep in mind to upgrade your code, if you are looking for sample code, please download MS CRM 2013 SDK you will get sample code, which should give you better understanding of MSCRM 2013 code standards.


Need help in CRM Contact US | Our Blog | Follow US | Like our Facebook Page | Our Book

Make sure to Vote as Helpful and  Mark As Answer ,if you get answer of your question.

Reply