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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans