System.Security.SecurityException: That assembly does not allow partially trusted callers

Topics: Developer Forum, User Forum
Jul 26, 2007 at 11:05 AM
I'm having problems with installing N2 CMS at shared hosting provider. After configuring the web.config, i'm getting the following error:

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: That assembly does not allow partially trusted callers.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

SecurityException: That assembly does not allow partially trusted callers.
N2.Engine.DefaultFactory..ctor() +0
N2.Factory.Initialize(Boolean forceRecreate) +73
N2.Web.InitializerModule.Init(HttpApplication context) +10
System.Web.HttpApplication.InitModules() +267
System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +1251
System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +243
System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +106
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +317

Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210

After some research, it seems that you need to change the trust level of the assembly ? Anyone experience with this problem?
Coordinator
Jul 26, 2007 at 2:10 PM
Hello Chiels,

Interesting problem. Apparently my hosting provider is more trusting than yours ;-) I think the problem is related to the way nhibernate does lazy loading using reflection and proxies.

I've been browsing through these links:
http://forum.castleproject.org/viewtopic.php?p=8393&sid=78efd390e32e8f37d744ca8f1d5706f1
http://www.webcontrolcenter.com/Knowledge_Base/frmKB.aspx?KBID=913

Rick Strahl suggest a solution changing web.config.
http://west-wind.com/WebLog/posts/5587.aspx

Please let me know if anything helps. I'll see if I can change the trust level on my machine to reproduce the problem. By the way, what hosting provider are you using?

/Cristian
Jul 26, 2007 at 6:59 PM
Edited Jul 26, 2007 at 6:59 PM
Thanks for the tips libarco. I'll will try it tomorrow when i'm back @ work (in about 12,5 hours) (holland gmt+1) :-) My hosting provider: http://www.is.nl/webfront/base.asp?pageid=195 (IS 200 package).

thnx in advance.

chiel
Coordinator
Jul 27, 2007 at 9:32 AM
Edited Jul 27, 2007 at 9:40 AM
I think your best option right now is to ask the hosting provider to lessen the restrictions a bit. I'll see if I can do any changes to the code make it run in a less trusting environment.

These are the changes I did on web_mediumtrust.config to make it run in "medium" trust:

<SecurityClass Name="ReflectionPermission" Description="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 
<SecurityClass Name="ConfigurationPermission" Description="System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 
and
  <IPermission class="ReflectionPermission" version="1" Unrestricted="true"  />
  <IPermission class="WebPermission" version="1" Unrestricted="true" />
  <IPermission class="ConfigurationPermission" version="1" Unrestricted="true" />
  <IPermission class="SecurityPermission" version="1" Unrestricted="true"  /> <!-- changed -->

I also compiled the castle libraries using AllowPartiallyTrustedCallers and without strong naming. Not sure you're going to need these but I'll post them here http://n2cms.com/upload/Castle_weakname_allowpartiallytrustedcallers.zip (you will need to re-reference these and recompile N2)

Good luck

/Cristian
Jul 30, 2007 at 10:02 AM
Hi libardo,

Thank you for the fast reply. I have contacted my ISP and it's not possible to change the trust level, because it's shared hosting. I tried to add a medium trust config but im receiving an application machine error (don't get it because it's not needed to declare the /edit directory as an application, for my local copy...). I'm using Microsoft Visual Web Developer 2005 Express Edition and for a strange reason, I even can't build/compile a fresh downloaded binary N2 release. Replacing the dll's is not an option indeed, like you mentioned above. Could you please compile N2 including the dll's using AllowPartiallyTrustedCallers and without strong naming? I would be very thankful.

Chiel
Coordinator
Jul 30, 2007 at 5:50 PM
I don't think recompiling will do you any good since the those permissions will be needed anyway just a bit later.

/Cristian
Coordinator
Aug 1, 2007 at 8:24 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Sep 25, 2007 at 2:41 PM

libardo wrote:
Interesting problem. Apparently my hosting provider is more trusting than yours ;-)


I have the same problem even my hosting provider (drundo) advertise that they fully support N2CMS.

Can u tell me which hosting u use which fully support N2?

Thanks.
Coordinator
Sep 26, 2007 at 7:37 AM
Edited Sep 26, 2007 at 7:38 AM
I have recently used http://www.space2u.com/.
/Cristian
Coordinator
Sep 29, 2007 at 5:49 PM
Any1 willing to to try an experimental medium trust module?

/Cristian
Sep 29, 2007 at 9:21 PM
I just switch to full trust hosting, but I can test it locally ....
Coordinator
Sep 30, 2007 at 3:38 PM
Thanks. I can wait until someone needs it. It requires a bit more verbose configuration.

/Cristian
Dec 21, 2007 at 7:04 AM
Edited Dec 21, 2007 at 7:05 AM
What is the status of N2.MediumTrust if I could ask? I was trying out the MediumTrustTest project. I can some errors in the Edit section.
Pressing the "Setting Button":
"NullReferenceException: Object reference not set to an instance of an object.]
N2.Edit.Web.UI.Controls.ServiceEditor.AddEditorsRecursive(Control container, IContainable contained) +101
N2.Edit.Web.UI.Controls.ServiceEditor.AddEditors() +85
N2.Edit.Web.UI.Controls.ServiceEditor.CreateChildControls() +31
System.Web.UI.Control.EnsureChildControls() +87
N2.Edit.Web.UI.Controls.ServiceEditor.OnInit(EventArgs e) +40
System.Web.UI.Control.InitRecursive(Control namingContainer) +321
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +692
"
Dec 21, 2007 at 7:06 AM
and trying to create a wizard page:

NameOccupiedException: An item named '' already exists below 'Index Page']
N2.Integrity.IntegrityEnforcer.OnItemSaving(ContentItem item) +117
N2.Integrity.IntegrityEnforcer.ItemSavingEvenHandler(Object sender, CancellableItemEventArgs e) +61
System.EventHandler`1.Invoke(Object sender, TEventArgs e) +0
N2.Persistence.NH.DefaultPersister.OnSaving(CancellableItemEventArgs args) +123
N2.Persistence.NH.DefaultPersister.Save(ContentItem unsavedItem) +98
N2.Edit.DefaultEditManager.HandleSave(IItemEditor itemEditor, ContentItem savedVersion) +144
N2.Edit.DefaultEditManager.Save(IItemEditor itemEditor, IPrincipal user) +166
N2.Web.UI.WebControls.ItemEditor.Save() +110
N2.Edit.Edit.OnSaveCommand(Object sender, CommandEventArgs e) +94
System.Web.UI.WebControls.CommandEventHandler.Invoke(Object sender, CommandEventArgs e) +0
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +105
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +163
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

Coordinator
Dec 21, 2007 at 10:32 AM
Hello potato =)

The status is slightly dormant. I've tried the core functionality but not ensured that all the features work in medium trust environments.

I do however, want it work as well as possible. I figure "settings" and "wizard" doesn't work. I'll look into that.

Thank you for letting me know about this and please post any other problems you find.

/Cristian
Coordinator
Dec 26, 2007 at 1:26 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.