Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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!

or

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

share|improve this question
    
You are not trying to a a Visual Web Part to the sandbox, by any chance? –  C. Marius - MVP Feb 14 '13 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 –  James Buckingham Feb 14 '13 at 21:51
add comment

2 Answers

up vote 3 down vote accepted

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.