SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Can you post a little more code, like exactly how you are using SPSecurity.RunWithElevatedPrivileges() – Dave Wise Feb 21 '13 at 19:30
up vote 2 down vote accepted

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.

share|improve this answer
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 '13 at 15:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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