Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

[CRM 2011 - Plugin - Sandbox - Database] Cannot execute Associate method - Inheritance security rules violated error

$
0
0

Hi all,

I have a problem while trying to execute associate method in plugin context (Post Create and Post Update). The dll is deployed in database with isolation mode = sandbox.

I have Account and Contact entities with primarycontactid and contact_customer_accounts relationships. They're all OOTB features. Now, I write a plugin which check if the primarycontactidfield is not full, it will be add to Account's contact_customer_accountsrelationship. Very simple isn't it? But I got this error when execute Associate method:

System.TypeLoadException: 
Inheritance security rules violated while overriding member: 
'Microsoft.Crm.Services.Utility.DeviceRegistrationFailedException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. 
Security accessibility of the overriding method must match the security accessibility of the method being overriden.

This is my code:

using System;
using Microsoft.Xrm.Sdk;

...

 Entity targetEntity = context.InputParameters["Target"] as Entity;
            if (targetEntity != null && targetEntity.LogicalName == "account")
            {
                IOrganizationService service = factory.CreateOrganizationService(context.UserId);
                if (targetEntity["primarycontactid"] != null)
                {
                    EntityReference contactRef = targetEntity["primarycontactid"] as EntityReference;
                    if (contactRef != null)
                    {
                        Relationship relationship = new Relationship("contact_customer_accounts");
                        EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
                        relatedEntities.Add(contactRef);
                        service.Associate(targetEntity.LogicalName, targetEntity.Id, relationship, relatedEntities);
                    }
                }
            }

NOTE: This code works perfectly fine with dll is deployed in database with isolation mode = None.

Thanks,

Please help me with this issue.


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>