Thursday, November 17, 2011

Working with 3rd party assemblies in Sandboxed solutions

If you are attempting to utilize 3rd party assemblies in SharePoint Sandboxed Solutions, you may encounter error messages when attempting to deploy your SharePoint project.

The reason this does not work is because Sandboxed Solutions run in partial trust, therefore, any assemblies that you utilize need to support a partial trust model.

If you are fortunate enough to have the source code for the assembly, then you can add the following attribute to the AssemblyInfo.cs file (in the case of C# source code): [assembly:AllowPartiallyTrustedCallers].  You can read more about this attribute here:  http://support.microsoft.com/kb/839300
You can then re-compile the source code and use the resultant assembly within your Sandboxed Solution. 

NOTE: When you add the Reference to your Visual Studio project, make sure that the property for "Copy Local" is set to True.  This will force the assembly to be copied to your bin directory and thereby include it in the WSP (SharePoint Solution Package) for deployment to your Site Collection.

As you can probably guess, if you do not have the source code to the assembly and it is not already marked to support partial trust, you are out of luck and will have to deploy your solution as a Farm Level Solution instead.  This is extremely unfortunate since online hosted solutions of SharePoint such as SharePoint Online/Office 365 only support Sandboxed Solutions--thereby making more complex application development solutions impossible. 



No comments:

Post a Comment