1

strong text [Plugin error at Note entity][1]

  [1]: https://i.stack.imgur.com/hRIi9.png

Hi,Anyone resolved my issue i got a Plug-in error which i worked at Update of "Note" entity.Basically i want a Plugin which converted pre-exiting Note attachment XML file into new .MMP extension file with the same name. I have done following procedure firstly i created a "Converter_Code.cs" dll which contains Convert() method that converted XML file to .MMP file here is the constructor of the class.

 public Converter(string xml, string defaultMapFileName, bool isForWeb)
      {
         Xml = xml;
         DefaultMapFileName = defaultMapFileName;
         Result = Environment.NewLine;
         IsForWeb = isForWeb;
         IsMapConverted = false;
         ResultFolder = CreateResultFolder(MmcGlobal.ResultFolder);
      }

In ConvertPlugin.cs Plug-in class firstly i retrieved Note entity attachment XML file in a string using following method in

  IPluginExecutionContext context =(IPluginExecutionContext)serviceProvider.
                               GetService (typeof(IPluginExecutionContext));
 IOrganizationServiceFactory serviceFactory= (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
 IOrganizationService service = serviceFactory.CreateOrganizationService
                               (context.UserId);
   if (context.InputParameters.Contains("Target")  
           && context.InputParameters["Target"] is Entity)
       {
        // Obtain the target entity from the input parameters.
        Entity entity = (Entity)context.InputParameters["Target"];
        var annotationid = entity.GetAttributeValue<Guid>("annotationid");
        if (entity.LogicalName != "annotation")
        {
          return;
        }
        else
        {
          try
         {
           //retrieve annotation file
         QueryExpression Notes = new QueryExpression { EntityName ="annotation"
        ,ColumnSet = new ColumnSet("filename", "subject", "annotationid",  
                     "documentbody") };
        Notes.Criteria.AddCondition("annotationid", ConditionOperator.Equal,  
                                    annotationid);
        EntityCollection NotesRetrieve = service.RetrieveMultiple(Notes);
        if (NotesRetrieve != null && NotesRetrieve.Entities.Count > 0)
        {
         {
           //converting document body content to bytes
           byte[] fill = Convert.FromBase64String(NotesRetrieve.Entities[0]
                         .Attributes["documentbody"].ToString());
            //Converting to String
           string content = System.Text.Encoding.UTF8.GetString(fill);
           Converter objConverter = new Converter(content, "TestMap", true);
           objConverter.Convert();
          }
         }
        }
          catch (FaultException<OrganizationServiceFault> ex)
         {
          throw new InvalidPluginExecutionException("something is going wrong");
         }
        }
       }
        }

and than A string is passed to "Converter" constructor as a parameter. finally i merged all dll using ILMerge following method: ilmerge /out:NewConvertPlugin.dll ConvertPlugin.dll Converter_Code.dll and NewConvertPlugin is registered successfully but while its working its generate following error:

Unexpected exception from plug-in (Execute): ConverterPlugin.Class1: System.Security.SecurityException: That assembly does not allow partially trusted callers. i also debug the plugin using Error-log but its not worked so i could not get a reason whats going wrong.

Santosh Rawat
  • 61
  • 1
  • 12

1 Answers1

1

The error is caused by the library you merged inside your plugin.

First of all you are using CRM Online (from your screenshot) and with CRM Online you can use only register plugins inside sandbox.

Sandbox means that your plugins are limited and they run in a partial-trust environment.

You merged an external library that requires full-trust permissions, so your plugin can't work and this is the reason of your error.

Because you are in CRM Online, or you find another library (the Converter) that requires only partial-trust, hoping that the merge process will work, or you include (if you have it) the source code of the converter library directly inside your plugin.

Guido Preite
  • 14,905
  • 4
  • 36
  • 65