web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by 7,316

Hi,

My plugin throws this exception on 'OrganizationServiceProxy'.

OrganizationServiceProxy orgService = new OrganizationServiceProxy(organizationUri, homeRealmUri, clientCredentials, null);

An exception of type 'System.Security.SecurityException' occurred in Microsoft.Xrm.Sdk.dll but was not handled in user code

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

Here is one if my plugin methods where this exception occurs: Here I am trying to get sharepoint location

public static string GetSharePointLocation(string entAccountID)
        {
            try
            {
                
                ClientCredentials clientCredentials = new ClientCredentials();
                clientCredentials.UserName.UserName = @"abc\xxxx";
                clientCredentials.UserName.Password = "xxxxxxx";


                Uri organizationUri = new Uri("xxxxxxxx/.../Organization.svc");

                Uri homeRealmUri = null;

                OrganizationServiceProxy orgService = new OrganizationServiceProxy(organizationUri, homeRealmUri, clientCredentials, null);

                orgService.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
                Guid guidSPDocLoc = RetrieveSharePointLocation(orgService, entAccountID);
                string absouteUrl = GetAbslouteUrl(orgService, guidSPDocLoc);

                orgService.Dispose();

                return absouteUrl;
            }
            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
            {
                return ex.Message;
            }
        }

Somebody please guide me in resolving this issue.
 Thanks for any help.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Hi

    The issue is that you are creating a new OrganizationServiceProxy rather than using the service provided by the plugin context. Sandbox plugins cannot create connections using windows credentials like this. Instead use the plug in context.

  • meenoo Profile Picture
    7,316 on at

    Thanks Scott.

  • Community Member Profile Picture
    on at

    Hi Steve,

    I've got the same error but i am not creating the OrganizationServiceProxy

    internal LocalPluginContext(IServiceProvider serviceProvider)
    {
    if (Equals(serviceProvider, null))
    {
    throw new ArgumentNullException("serviceProvider");
    }
    ServiceProvider = serviceProvider;
    // Obtain the execution context service from the service provider.
    PluginExecutionContext = serviceProvider.GetService(typeof(IPluginExecutionContext)) as IPluginExecutionContext;

    // Obtain the tracing service from the service provider.
    TracingService = serviceProvider.GetService(typeof(ITracingService)) as ITracingService;

    // Obtain the organization service factory from the service provider.
    var factory = serviceProvider.GetService(typeof(IOrganizationServiceFactory)) as IOrganizationServiceFactory;
    if (factory == null)
    {
    throw new InvalidPluginExecutionException("Unable to get OrganizationServiceFactory");
    }

    // Use the factory to generate the Organization Service
    if (PluginExecutionContext != null && (!Equals(PluginExecutionContext.UserId) && PluginExecutionContext.UserId != Guid.Empty))
    {
    OrganizationService = factory.CreateOrganizationService(PluginExecutionContext.UserId);
    }
    else
    {
    // Impersonate as system
    OrganizationService = factory.CreateOrganizationService(null);
    }
    }

    any ideas?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans