1
votes

I have a simple post create plugin on the Account entity that makes a subsite in SharePoint online with the same name of the Account that has been created.

I have used the SharePointOnlineCredentials class from the Microsoft.SharePoint.Client.Runtime assembly to login to the SharePoint instance.

The plugin works on an on-premise instance as long as the plugin is set to isolation mode = none.

When I run the plugin in Sandbox isolation mode I get the error below (online version error).

I want to run this plugin on an online instance of SharePoint, but as, I believe, I cannot run online with an isolation mode = none, is there another way of running code using this SharePoint assembly on an online CRM instance?

Message: Create, Method: ExecutePluginLogic Exception: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.    at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)    at System.Security.CodeAccessPermission.Demand()    at System.Net.AuthenticationManager.Register(IAuthenticationModule authenticationModule)    at

Microsoft.SharePoint.Client.SharePointOnlineAuthenticationModule.EnsureRegistered()    at Microsoft.SharePoint.Client.SharePointOnlineCredentials..ctor(String username, SecureString password)    at

MWLSPXRMToolkitOnline.Plugins.AccountCreate.ExecutePluginLogic(IServiceProvider serviceProvider)    at MWLSPXRMToolkitOnline.Plugins.BasePlugin.Execute(IServiceProvider serviceProvider)

The action that failed was: Demand The type of the first permission that failed was:

System.Security.Permissions.SecurityPermission The Zone of the assembly that failed was: MyComputer

2

2 Answers

1
votes

Not sensibly, when running in Sandbox mode you can't include references to other assemblies. You could try using ILMerge to combine the assemblies together, but if I was you I would take a different approach, e.g. pushing work to an external web service.

0
votes

If using ILMerge to combine the assemblies together(as recommended by James Wood because when running in Sandbox mode you can't include references), use the '/copyattrs' parameter with ILMerge. If you have installed ilMarge in the project with NuGet package:

Editing the file in solution:ILMerge.props Change parameters:

<ILMergeAllowMultipleAssemblyLevelAttributes>true</ILMergeAllowMultipleAssemblyLevelAttributes>
<ILMergeCopyAttributes>true</ILMergeCopyAttributes>