Error validating exception when using System.Reflection

713 views Asked by At

We're developing a SharePoint webpart as a sandboxed solution in Visual Studio 2013 for SharePoint Online. We use an external dll library iTextSharp for reading and writing to PDF. We are having a problem when activating our solution.

Our error message is:

Error validating assembly itextsharp.dll.

This solution references prohibited type System.Reflection.BindingFlags and cannot be used on this site collection.

1

There are 1 answers

0
Michael A On

You've answered this question yourself already:

This solution references prohibited type System.Reflection.BindingFlags and cannot be used on this site collection.

You can't use the System.Reflection namespace with SharePoint Online solutions (for the most part). The only allowed members from System.Reflection are:

  • GetValue Name
  • GetCustomAttributes
  • PropertyType
  • GetValue SetValue

I recommend taking a look at Microsoft's documentation for developing SharePoint Online solutions (link) as there are quite a few namespaces previously available for SharePoint development that are now prohibited.

Here's what Microsoft has to say about this:

Because it is a multi-tenant environment, when you upload a sandboxed solution to the Solution Gallery, SharePoint Online performs a further round of validation checks, in addition to those performed by on-premise SharePoint installations. A sandboxed solution cannot be activated if it contains code calling any of the following namespaces:

And here's the list of prohibited namespaces (see documentation for all exceptions):

  • Microsoft.SqlServer
  • Microsoft.Win32
  • System.Data.Sql
  • System.Data.SqlClient
  • System.Data.SqlTypes
  • System.IO.Pipes
  • System.IO.Ports
  • System.Reflection
  • System.Runtime.InteropServices
  • System.Runtime.Remoting
  • System.Threading
  • Array.CreateInstance()
  • System.Delegate
  • Type.GetType(String)
  • Type.InvokeMember()