I created an ASP.net webapplication and i have used assemblies Microsoft.SharePoint; and Microsoft.Office.Server.UserProfiles in it.. i get a run time error

"Could not load file or assembly 'Microsoft.Sharepoint.Sandbox' or one of its dependencies. An attempt was made to load a program with an incorrect format. "

in it.

How to resolve this?

3 Answers 3


From microsoft and i agree, you need the correct version from the gac and reference it into your project. Once you add the reference you need to set "copy to local" as false ;)

this will work and what i would do if i ran into any dll issue!

step by step:

To copy the dll, goto start - select or search for "run" and copy past this code:



add reference to your project, right click on the reference Microsoft.SharePoint.Sandbox.dll and click on "properties" set copy to local = false

dll copy to loacal = false

build and run project, should work fine :)



According to this blog post by Louis Liang, the workaround is to add a post-build event and delete the DLL:

cd $(TargetDir)
del Microsoft.SharePoint.SandBox.dll

Taken from :



If you created an ASP.NET Web Application that it going to run outside of SharePoint (i.e. on a different server or in a different App Pool on the same server), then you cannot use the assemblies you referenced. They are part of the Server Object Model and need to run in the context of SharePoint. For remote applications you need to use the Client Object Model (Microsoft.SharePoint.Client.*), the REST API, or the SOAP Web Services.

Your Answer

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

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