SBX - Search With Button

SBX - Forum Post Title

Plugin error

Microsoft Dynamics CRM Forum

Itz_Me_Ram asked a question on 30 Oct 2017 12:49 PM

Question Status

Unanswered

I'm trying to debug a plugin by downloading the log file and attaching it to the plugin registration tool. I started the profiler and recreated the issue. I see that the error below : 

"Unexpected exception from plug-in (Execute): PluginProfiler.Plugins.ProfilerPlugin: System.Security.SecurityException: The data contract type 'Microsoft.Xrm.Sdk.OrganizationServiceFault' cannot be serialized in partial trust because the property 'ExceptionRetriable' does not have a public getter."

Any suggestions/Info on this?

Thank you.

Reply
elebasi responded on 2 Feb 2018 4:42 AM
My Badges

Same here

Reply
Michel Gueli responded on 2 Feb 2018 4:58 AM
My Badges

Are you using the right Version of the pluginregistrationtool?

Reply
Michael Mittermair responded on 2 Feb 2018 6:40 AM
My Badges

Based on the exception I assume, your plugin is registered in the Sandbox-Mode. In the Sandbox, not all operations are allowed. This is indicated by 'partial trust'. You can try to register your plugin in none-sandbox-mode and/or make your dll fully-trusted

Reply
Suresh_Satti responded on 2 Feb 2018 7:46 AM

I have run into the exact error as said in the initial post. In my case, i am trying to run a queryexpression. The same piece of code runs fine when i try using querybyattribute. Is there any suggestion that you would like to give. I am running the plugin in sandbox, i am not sure if my plugin dll is fully-trusted, please help with the steps that would help me make the dll fully trusted.

Reply
Michael Mittermair responded on 2 Feb 2018 7:49 AM
My Badges

Can you paste the piece of code, that is causing the error, maybe it's easier to understand the error

Reply
Suresh_Satti responded on 2 Feb 2018 7:53 AM

The commented part runs fine i.e. querybyattribute, but the rest is for Queryexpression that is what is problematic.

               //QueryByAttribute query = new QueryByAttribute { EntityName = "account", ColumnSet = new ColumnSet("name", "address1_city") };

               // query.AddAttributeValue("statecode", 0);

               //query.PageInfo.ReturnTotalRecordCount = true;

               ConditionExpression condition1 = new ConditionExpression();

               condition1.AttributeName = "address1_city";

               condition1.Operator = ConditionOperator.Contains;

               condition1.Values.Add("Red");

               FilterExpression filter1 = new FilterExpression();

               filter1.Conditions.Add(condition1);

               QueryExpression query = new QueryExpression("account");

               query.ColumnSet.AddColumns("name", "address1_city");

               query.Criteria.AddFilter(filter1);

               EntityCollection results = service.RetrieveMultiple(query);

Reply
Michel Gueli responded on 2 Feb 2018 8:51 AM
My Badges

I've updated your code:

var query = new QueryExpression("account");

query.PageInfo.ReturnTotalRecordCount = true; //Why use this line????

query.ColumnSet.AddColumn("name");

query.ColumnSet.AddColumn("address1_city");

query.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);

query.Criteria.AddCondition("address1_city", ConditionOperator.Contains, "Red");

EntityCollection results = service.RetrieveMultiple(query);

Reply
Suresh_Satti responded on 2 Feb 2018 9:28 AM

Still the same. See the below error.

Reply
Michael Mittermair responded on 3 Feb 2018 9:56 AM
My Badges

Hi,

try the following:

public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context from the service provider.
            Context =
                (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            // Get a reference to the Organization service.
            var factory =
                (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            OrgService = factory.CreateOrganizationService(Context.UserId);

            var query =
                new QueryExpression("account")
                {
                    ColumnSet = new ColumnSet("name", "address1_city"),
                    Criteria =
                    {
                        Conditions =
                        {
                            new ConditionExpression("address1_city", ConditionOperator.Contains, "Red")
                        }
                    }
                };
            var result = OrgService.RetrieveMultiple(query);

            foreach (var items in result.Entities)
            {
                // do something
            }

......

Set the breakpoint to the foreach, not the OrgService.Ret....

Reply
Suresh_Satti responded on 3 Feb 2018 11:04 AM

Sorry to say, it still dosent work. I continue to get the same error. Please see the below complete code that i ran.

public class Class1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
var Context =
(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

// Get a reference to the Organization service.
var factory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var OrgService = factory.CreateOrganizationService(Context.UserId);

var query =
new QueryExpression("account")
{
ColumnSet = new ColumnSet("name", "address1_city"),
Criteria =
{
Conditions =
{
new ConditionExpression("address1_city", ConditionOperator.Contains, "Red")
}
}
};
var result = OrgService.RetrieveMultiple(query);

foreach (var items in result.Entities)
{
items.Attributes["new_countofallrecords"] = result.Entities.Count.ToString();
OrgService.Update(items);
}
}
}
}

Reply
Mir Hassan Ali responded on 4 Feb 2018 11:52 PM
My Badges

Hi Suresh

Can you try including the attribute 'new_countofallrecords' in your column set that you are retrieving.

Mir

Reply
Michel Gueli responded on 6 Feb 2018 2:59 AM
My Badges

Can you tell me what the requirement is? Why update each account?

I will also change this line: items.Attributes["new_countofallrecords"] = result.Entities.Count.ToString();

OrgService.Update(items);

Create a new entity object like this:

var updateAccount = new Entity("account")";

updateAccount .Id = items.Id;

updateAccount.Attributes.Add("new_countofallrecords", result.Entities.Count.ToString());

OrgService.Update(updateAccount);

Reply
Suresh_Satti responded on 20 Feb 2018 12:35 AM

Thank you All, i am not really sure what the problem was but when i tried the same code on new trial instance the code worked but gave an SQL error stating "Cannot use a CONTAINS or FREETEXT predicate on table" So i am guessing something was wrong with the previous instance and it couldnt handle the SQL error.

About the SQL error, it was because the account table wasnt full text indexed. In a Microsoft Dynamics 365 default installation, only the attributes of the KBArticle (article) entity are enabled for full-text indexing.

My issue got resolved by using LIKE instead of Contains.

Reply
Sai Kiran responded on 17 May 2019 12:33 PM
My Badges

My plugin was working good. I have added profiler and forgot to unprofile when unregistered the Assembly. Got this error when registered the plugin again.

Removing the profiled step for last version of assembly resolved it for me.

Reply

SBX - Two Col Forum

SBX - Migrated JS