0

My SharePoint 2010 solution comprises of 2 Features. One feature uses the Flee library to do some mathematical calculations in some code behind. The solution has a number of class libraries that I have written.

All are set to Target Framework .NET 3.5 and are signed.

The features are essentially made of Application Pages (with images/css for good measure).

All has been running smoothly. I changed deployment of the referenced class libraries from GAC to Web Application yesterday.

This morning when I booted up, IIS didn't start and therefore I could not deploy so I had to reboot. However, since the reboot and I have gone into the screen that uses the Flee in the code behind, it has started throwing the following exception:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Security Exception 
Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 


[No relevant source lines]


Source File: c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\a225d0da\83ec41b8\App_Web_editPlantdata.aspx_-758514286.qeqss8gf.0.cs    Line: 0 

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +54
   System.Reflection.Emit.DynamicMethod.PerformSecurityCheck(Type owner, StackCrawlMark& stackMark, Boolean skipVisibility) +269
   System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes, Type owner) +70
   Ciloci.Flee.Expression`1.CreateDynamicMethod() +473
   Ciloci.Flee.Expression`1.Compile(String expression, ExpressionOptions options) +491
   Ciloci.Flee.Expression`1..ctor(String expression, ExpressionContext context, Boolean isGeneric) +713
   Ciloci.Flee.ExpressionContext.CompileDynamic(String expression) +88
   XXXXXSSFDM.Layouts.XXXXXSSFDM.EditPlantData.ValidateDataRow(List`1 rowDataList, SPGridViewRow gridViewRow, ExpressionContext expressionContext) +1171
   XXXXXSSFDM.Layouts.XXXXXSSFDM.EditPlantData.ValidateData() +541
   XXXXXSSFDM.Layouts.XXXXXSSFDM.EditPlantData.SaveData() +166
   XXXXXSSFDM.Layouts.XXXXXSSFDM.EditPlantData.SaveButton_Click(Object sender, EventArgs e) +52
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11070247
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11069786
   System.Web.UI.Page.ProcessRequest() +91
   System.Web.UI.Page.ProcessRequest(HttpContext context) +240
   ASP.EDITPlantDATA_ASPX__758514286.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\a225d0da\83ec41b8\App_Web_editPlantdata.aspx_-758514286.qeqss8gf.0.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +599
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.5466; ASP.NET Version:2.0.50727.5456 

This is occurring in Ciloci.Flee. I have the Flee VB.NET source code project included in my solution and the same target framework and snk are set.

However, if I change the Flee Deployment Target back to GAC then it runs fine. Some security I have overlooked somewhere but can't see it at the minute.

I am still getting to grips with SharePoint and ASP.NET. I don't know whether I need to look at some configuration in ASP.NET. I will still look for solutions - thought someone could point me in the right direction.

1

When Microsoft introduced .Net the dream was that you could plug your software together as LEGO building blocks from any source. But this created one issue Security.

Normally in windows all permissions is based on the user running the code. But Microsoft introduced "Code Access Security"(CAS) in order to prevent that building software from components that you download should be a huge security risk.

In short CAS gives permission to code based on where it's loaded from and who wrote the software and this is combined with the permissions of the user. And in order to ensure that unsecure code isn't calling secure code and thereby do something the unsecure code shouldn't be able to every security check is done on the entire call stack (unless some level turns it off (which requires sufficient permissions)).

Due to performance CAS is turned off when DLLs are loaded from the GAC (using the assumption that only code you trust goes into the GAC).

Because CAS is complicated to set up most ASP.NET projects turns CAS off by specifying <trustLevel name="Full" \> in the web.config (this is done by default by Visual Studio and most projects don't change it).

So most .Net developers don't know CAS, which is also why it's been deprecated in .Net 4.0.

BUT SharePoint uses CAS when DLLs are deployed to the bin folder of the Web Application.

In the WSP package you can configure CAS see "Securing Web Parts in SharePoint Foundation", but you should ask yourselves if you want to go into all that trouble.

  • Yeah it's been over 6 years since I had to touch CAS. I've got a number of custom class libraries that I am deploying. The security exception now appears on a number of them. These are also shared with a Windows Service I have written, so I don't want to remove them from GAC should I need to when the solution is retracted. – Paul Anderson Jul 3 '13 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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