I'm trying to build my very first SP (2010) Sandbox project (I'm generally new to SP anyway!) but I keep hitting the following "infamous" error when I try and add any of my custom Web Parts to a page:-

Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: $Resources:core,ImportErrorMessage;

I've read numerous articles online that this is normally to do with the issues like trying to use references to classes prohibited by the Sandbox. What's odd though is that even if I introduce a completely empty Web Part and try and deploy this I either get that error above or this appearing in the Web Part's page location instead of the WP:-

 Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: The type is not registered as safe.

Debug doesn't seem to work for me at the moment either. If I try to run it I either get:-

a) Visual Studio telling me my code is not the same as the version currently running - which 9 times out of 10 it is!


b) That the first error is being thrown before I even hit the Web Part code and my breakpoints are ignored.

A bit of background on the project might help:-

I've setup the following structure...

  • Project1
  • Project2
  • Core (Common Project Assets)

Project1 and Project2 inherit from the functionality setup in the Core.

Introduction of the 2nd project and the core seems to have been when the issues started to appear but again the empty Web Part of Project1 doesn't call anything from Core so I'm not 100% that's where the problem lies.

  • Each project is defined as a Sandbox solution. Each Web Part is a standard one, not a Visual or a Visual (Sandboxed).

  • It was mentioned that separate Solutions trying to communication might be an issue so I've refactored and am now deploying all my projects under one, separate WSP.

  • I've checked that the AssemblyInfo includes a reference to [assembly: AllowPartiallyTrustedCallers()] and that's on all the projects.

  • I've tried clearing out the Solution, changing the Assembly version numbering before deployment nothing makes a difference.

So I'm now at a point where I'm not sure what else to try and Googling isn't giving me much luck either. Does anyone have any ideas?

Thanks in advance, James

  • You are not trying to a a Visual Web Part to the sandbox, by any chance? Commented Feb 14, 2013 at 21:38
  • Hi C. See my first bullet point in the last section. It's a standard Web Part - not Visual. Just to add, the Web Part now erroring did work previously but with the refactor with project 2 and core being introduced I'm now seeing this. Thanks Commented Feb 14, 2013 at 21:51

2 Answers 2


Well it's taken a few days but I've finally managed to work this one out however it did involve me having to dissect the whole project and reintroduce each piece one at a time.

A few issues were causing it:-

1) I had set one of the projects "Include Assembly in Package" property to false.

2) A static method was making a call to an SPList which turned an empty (null) value. Added a value to that item and the error disappeared.

3) I'd declared a variable as being of type double and set its default value as 0.

Now why the system couldn't have told me that's what the problems were rather than throwing this generic error is a different story! It would have saved me many an hour of confusion.

Thanks all for your input though, it's much appreciated

  • How does one properly go about debugging something like this. I am getting this bug when running my web part, but I am having trouble finding the bugs, and can't really debug if I never get to run the web part...
    – cm2
    Commented May 12, 2015 at 21:40

Did you try to restart the SPUC service and try again? Also, it is a good option to try to change the service account which runs SPUC service to farm admin and try to see if it works. Because, I am sure I did face these annoying exceptions sometime back and one of the above option solved it.

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.