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 am testing out Visual Studio 2010.

I have created a sandboxed solution with a webpart. It deployed OK.

I then tried adding a dll to the solution that would contain the business logic. This dll is signed with it's own strong name key.

We I now deploy the solution, I get the following error when the code tries to use the business logic dll:

Web Part Error: Unhandled exception was thrown by the user code wrapper's Execute method in the partial trust app domain: System.Security.SecurityException: That assembly does not allow partially trusted callers. at SharePointProject1.WebPart1.WebPart1.button_Click(Object sender, EventArgs e) at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at Microsoft.SharePoint.UserCode.SPUserCodeWebPartWrapper.ExecuteHttpRequest(SPUserCodeWebPartHttpRequestContext webPartExecutionContext, SPUserCodeWebPartHttpResponse httpRequestResponse) at Microsoft.SharePoint.UserCode.SPUserCodeWebPartWrapper.Execute(SPUserCodeExecutionContext executionContext) at Microsoft.SharePoint.UserCode.SPUserCodeApplicationHostAppDomainRef.Execute(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, Byte[] binaryUserCodeToken, Byte[] proxyOperationToken, SPUserCodeExecutionContext executionContext) The action that failed was: LinkDemand The assembly or AppDomain that failed was: SharePointProject1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0b5230b1615a26d4 The method that caused the failure was: System.String Toggle(System.String) The Zone of the assembly that failed was: MyComputer The Url of the assembly that failed was: file:///C:/ProgramData/Microsoft/SharePoint/UCCache/8CCB51CC8164124/CF0F683C1542422E80050AFD2BD3D785%2DHbWRnjvb49VmZuA5OCXjhZbPX0JMH5a6kSdXvb4VoxE%3D-8/SharePointProject1.dll

Anybody know how to fix this?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Is the business logic assembly in GAC?

If so add APTCA to your assembly.cs to allow your partially trusted code to call it [assembly:System.Security.AllowPartiallyTrustedCallersAttribute()]

Edit: Since your sandboxed code is not running full trust, i'm pretty sure (somebody correct me if im wrong) you will also get the error if your business logic isnt in the GAC, since strongly named assemblies cannot be called by partially trusted assemblies.

Also before you decorate your assembly with the above attribute you should scrutinize your business logic for security vulnerabilities to avoid luring attacks.

Shawn Farkas has an article on the attribute here.

share|improve this answer
    
Anders is correct. If your BL is in the GAC you cannot call it from the sandbox. –  Wictor Wilen MCA MCM MVP Apr 28 '10 at 21:43
    
Thanks, it looks like the solution is to place the business logic as a separate class within the UI DLL. –  Shiraz Bhaiji Jul 9 '10 at 8:59
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.