ILMerge with CRM plugin and Sharepoint Online

假装没事ソ 提交于 2019-12-24 19:40:28

问题


I am trying to us ILMerge via nuget to merge two SharePoint assemblies in to my plugin dll. The assemblies are;

Microsoft.SharePoint.Client  (v16.1)
Microsoft.SharePoint.Client.Runtime (v16.1)

They seem to successfully merge in to my single plugin dll and i can see the required classes etc if I inspect the dll with JustDecompile.

When debugging the plugin, it throws a security exception;

Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0

The code successfully steps over the creation of 'ClientContext()' which is located in the Microsoft.SharePoint.Client dll, but then fails when it reaches the 'new SharePointCredentials()' line which is held in the Microsoft.SharePoint.Client.Runtime dll.

    using (var srcContext = new ClientContext(url))
    {
        srcContext.Credentials = new SharePointOnlineCredentials(username, securePassword);

I am stuck as to why this might be happening. It is Dynamics 365 online and SharePoint online. The credentials supplied to the constructor are correct. Any pointers would be greatly appreciated. I really don't want to have to create a web service instead of ILMerging the SharePoint dlls.


回答1:


This is almost undoubtedly related to the to the method being called requiring permissions that Dynamics 365 Online does not allow. That is usually the cause of a System.Security.Permissions.SecurityPermission error in a Plugin/Workfrom running in Dynamics 365 Online.

It's been a longtime, but if memory serves me correctly the SharePoint client libraries do not work in Dynamics 365 sandbox plugins (and all online plugins are in the sandbox.)

Unless you can find a way to make the calls without the libraries, using the SharePoint REST API, you'll have to either create a web service or (in my opinion the preferable if possible solution is to) use Azure Service Bus to handle the execution.




回答2:


As Nick says, unfortunatelly Sharepoint.client.dll will throw you a “System.Security.SecurityException: That assembly does not allow partially trusted callers” error even if you use ILMerge to deploy it.

It is a limitation from Sandbox and there is nothing we can do until Microsoft deals with this.

But for the time being, the best way is to do oldschool httprequests as explained here: https://code.msdn.microsoft.com/SharePoint-Integration-c5f21604

Good Luck!



来源:https://stackoverflow.com/questions/48830692/ilmerge-with-crm-plugin-and-sharepoint-online

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!