Papi
Papi

Reputation: 555

CRm Dynamics 2013 Plugin Error, Request for the permission of type xxx failed

I have a CRM Plugin that fires on an update of a field on the form, the plugin then should utilize the Import capabilities of the SDK to Import CSV Records into Dynamics, I get the foloowing error

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

I have registered the Plugin in Isolation Mode set to NONE, not Sandbox but I still get the error, any Ideas as to why this is happening and how I can resolve it. It fails on the ImportFile part which is encapsulated in the ImportData function.

Please see my Plugin Code below

public void Execute(IServiceProvider serviceProvider)
    {
        ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
        IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

        if (context == null)
        {
            throw new ArgumentNullException("loaclContext");
        }

        if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
        {
            Entity supplyClaimsEntity = (Entity)context.InputParameters["Target"];

            if (supplyClaimsEntity.LogicalName != "new_supplierclaimsupdate")
            {
                return;
            }

            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

            IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);

            string entityBeginUpload = "Start Upload";
            try
            {

                string filePath = (@"C:\Team CRM\Warp.csv");

                ImportData(service, new_topproducts.EntityLogicalName, filePath);

            }

            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
            {
                Console.WriteLine("The application terminated with an error.");
                Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp);
                Console.WriteLine("Code: {0}", ex.Detail.ErrorCode);
                Console.WriteLine("Message: {0}", ex.Detail.Message);
                Console.WriteLine("Inner Fault: {0}",
                    null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
            }
            catch (System.TimeoutException ex)
            {
                Console.WriteLine("The application terminated with an error.");
                Console.WriteLine("Message: {0}", ex.Message);
                Console.WriteLine("Stack Trace: {0}", ex.StackTrace);
                Console.WriteLine("Inner Fault: {0}",
                    null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("The application terminated with an error.");
                Console.WriteLine(ex.Message);

                // Display the details of the inner exception.
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);

                    FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException
                        as FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>;
                    if (fe != null)
                    {
                        Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp);
                        Console.WriteLine("Code: {0}", fe.Detail.ErrorCode);
                        Console.WriteLine("Message: {0}", fe.Detail.Message);
                        Console.WriteLine("Trace: {0}", fe.Detail.TraceText);
                        Console.WriteLine("Inner Fault: {0}",
                            null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
                    }
                }
            }

Upvotes: 0

Views: 1102

Answers (2)

Daryl
Daryl

Reputation: 18895

Assuming this is a synchronous (Asynchronous could potentially be running on a different server, depending on your deployment) plugin, check that the IIS Account the user is running as has rights to the folder. If it doesn't then you'll get the file permission error that you are seeing.

Upvotes: 1

MaPi
MaPi

Reputation: 1601

Are you running the plugin on an online organisation? In that case you can't set the organisation set to mode when you register the assembly.

Upvotes: 0

Related Questions