I am trying to use a legacy C++ dll that has around 5 C/C++ dependencies in SharePoint. I created a wrapper for the dll and it works fine in a test desktop program. I added the wrapper and all C++ libraries to the event receiver assembly and they are being deployed to the WebApplication target. When I run the receiver I get

SecurityException was unhandled by user code System.Security.Permission.SecurityPermission

when it hits the C++ method.

Next, I tried using SPSecurity.RunWithElevatedPrivileges() in the wrapper but I get

SecurityException was unhandled by user code Microsoft.SharePoint.Security.SharePointPermission`.

How can I get the C++ library to work?

  • Can you post a little more code, like exactly how you are using SPSecurity.RunWithElevatedPrivileges()
    – Dave Wise
    Feb 21, 2013 at 19:30

1 Answer 1


This isn't a SP security issue, it's a file system security issue. Make sure the identity running this code has permissions to read the file system.


Make sure your C++ library has sufficient file permissions so that SharePoint can access it. You can match permissions with your development environment.

Other then that all I can think of is trust levels of your web application, check this link out that is explaining how trust levels are setup in different environment as your development machine web app might have full trust level.

  • I worked off your comment and was able to find this which allowed talked about AllowPartiallyTrustedCallers. Calling that assembly along with changing the web.config <trust level='Full'> allowed the dll to execute. Thanks for your help!
    – ewokwv
    Mar 14, 2013 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.