.NET 4.5 + (Custom) Medium Trust + Orchard

Topics: Troubleshooting
Aug 30, 2012 at 5:47 PM

Is Orchard functional under .NET 4.5 with Medium trust? I'm getting "Operation could destabilize the runtime." exception. Works fine under Full trust, but no dice with Medium or High.

Based on the stack trace looks like it's bubbling up from Autofac:

Operation could destabilize the runtime.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Security.VerificationException: Operation could destabilize the runtime.

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:

[VerificationException: Operation could destabilize the runtime.]
   Orchard.ContentManagement.Handlers.ActivatingFilter`1..ctor(String[] contentTypes) in ActivatingFilter.cs:17
   Orchard.Warmup.Handlers.WarmupSettingsPartHandler..ctor(IRepository`1 repository) +79

[DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Orchard.Data.IRepository`1[Orchard.Warmup.Models.WarmupSettingsPartRecord])' on type 'WarmupSettingsPartHandler'.]
   Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +223
   Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +184
   Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
   Autofac.Core.Resolving.InstanceLookup.<Execute>b__6() +7
   Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +112
   Autofac.Core.Resolving.InstanceLookup.Execute() +132
   Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +164
   Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +24
   Autofac.Features.Collections.<>c__DisplayClass6.<RegistrationsFor>b__1(IComponentRegistration cr) +17
   System.Linq.WhereSelectArrayIterator`2.MoveNext() +66
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +335
   System.Linq.Enumerable.ToArray(IEnumerable`1 source) +77
   Autofac.Features.Collections.<>c__DisplayClass4.<RegistrationsFor>b__0(IComponentContext c, IEnumerable`1 p) +138
   Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +30
   Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
   Autofac.Core.Resolving.InstanceLookup.Execute() +48
   Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +164
   Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +24
   Autofac.Core.Registration.<>c__DisplayClass8.<RegistrationsFor>b__3(IComponentContext c, IEnumerable`1 p) +19
   Autofac.Builder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p) +14
   Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +30
   Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
   Autofac.Core.Resolving.InstanceLookup.Execute() +48
   Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +164
   Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) +64
   Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +158
   Autofac.Features.LazyDependencies.<>c__DisplayClass7.<CreateLazyRegistration>b__4() +23
   System.Lazy`1.CreateValue() +180
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +22
   System.Lazy`1.get_Value() +10749357
   Orchard.ContentManagement.DefaultContentManager.New(String contentType) in DefaultContentManager.cs:76
   Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options, QueryHints hints) in DefaultContentManager.cs:199
   Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options) in DefaultContentManager.cs:111
   Orchard.ContentManagement.DefaultContentQuery.<Slice>b__0(ContentItemVersionRecord x) in DefaultContentQuery.cs:148
   System.Linq.WhereSelectListIterator`2.MoveNext() +104
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +381
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
   Orchard.ContentManagement.DefaultContentQuery.Slice(Int32 skip, Int32 count) in DefaultContentQuery.cs:146
   Orchard.ContentManagement.ContentQuery`1.Orchard.ContentManagement.IContentQuery<T>.Slice(Int32 skip, Int32 count) in DefaultContentQuery.cs:195
   Orchard.Core.Settings.Services.SiteService.<GetSiteSettings>b__0(AcquireContext`1 ctx) in SiteService.cs:30
   Orchard.Caching.Cache`2.CreateEntry(TKey k, Func`2 acquire) in Cache.cs:57
   Orchard.Caching.<>c__DisplayClass2.<Get>b__0(TKey k) in Cache.cs:19
   System.Collections.Concurrent.ConcurrentDictionary`2.AddOrUpdate(TKey key, Func`2 addValueFactory, Func`3 updateValueFactory) +125
   Orchard.Caching.Cache`2.Get(TKey key, Func`2 acquire) in Cache.cs:17
   Orchard.Caching.DefaultCacheManager.Get(TKey key, Func`2 acquire) in DefaultCacheManager.cs:33
   Orchard.Core.Settings.Services.SiteService.GetSiteSettings() in SiteService.cs:29
   Orchard.Settings.CurrentSiteWorkContext.Get(String name) in CurrentSiteWorkContext.cs:13
   Orchard.Environment.<>c__DisplayClass7`1.<FindResolverForState>b__2(IWorkContextStateProvider wcsp) in WorkContextImplementation.cs:32
   System.Linq.WhereSelectArrayIterator`2.MoveNext() +66
   System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate) +161
   Orchard.Environment.WorkContextImplementation.FindResolverForState(String name) in WorkContextImplementation.cs:32
   System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72
   Orchard.Environment.WorkContextImplementation.GetState(String name) in WorkContextImplementation.cs:27
   Orchard.WorkContext.get_CurrentSite() in WorkContext.cs:52
   Orchard.Widgets.Filters.WidgetFilter.OnResultExecuting(ResultExecutingContext filterContext) +1275
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +41
   System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +22
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
   System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +22
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +245
   System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +22
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +176
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311
   System.Web.Mvc.Controller.ExecuteCore() +105
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +87
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in ShellRoute.cs:147
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629708
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155



Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

Aug 30, 2012 at 5:52 PM

Should have mentioned, this is a new "clean" Orchard 1.5.1 pulled down via WebMatrix from the current WebPI4 feed and deployed via WebMatrix.

-Mike

Coordinator
Sep 13, 2012 at 12:25 AM

It should be, yes. Otherwise it's a bug that should be filed. Why do you need medium trust?

Sep 20, 2012 at 11:27 PM

I'm having the same issue with 1.5.1. I'm using Shared Hosting from OrcsWeb (One of the major hosting providers), and getting the same issue as above:

[VerificationException: Operation could destabilize the runtime.]
   Orchard.ContentManagement.Handlers.ActivatingFilter`1..ctor(String[] contentTypes) in ActivatingFilter.cs:17
   Orchard.Search.Handlers.SearchSettingsPartHandler..ctor(IRepository`1 repository) +92

[DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Orchard.Data.IRepository`1[Orchard.Search.Models.SearchSettingsPartRecord])' on type 'SearchSettingsPartHandler'.]
   Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +223
   Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +184
   Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
   Autofac.Core.Resolving.InstanceLookup.b__6() +7
   Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +112
   Autofac.Core.Resolving.InstanceLookup.Execute() +132
   Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +164
   Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +24
   Autofac.Features.Collections.<>c__DisplayClass6.b__1(IComponentRegistration cr) +17
   System.Linq.WhereSelectArrayIterator`2.MoveNext() +66
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +335
   System.Linq.Enumerable.ToArray(IEnumerable`1 source) +77
   Autofac.Features.Collections.<>c__DisplayClass4.b__0(IComponentContext c, IEnumerable`1 p) +138
   Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +30
   Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
   Autofac.Core.Resolving.InstanceLookup.Execute() +48
   Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +164
   Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +24
   Autofac.Core.Registration.<>c__DisplayClass8.b__3(IComponentContext c, IEnumerable`1 p) +19
   Autofac.Builder.<>c__DisplayClass1`1.b__0(IComponentContext c, IEnumerable`1 p) +14
   Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +30
   Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +48
   Autofac.Core.Resolving.InstanceLookup.Execute() +48
   Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +164
   Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) +64
   Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) +158
   Autofac.Features.LazyDependencies.<>c__DisplayClass7.b__4() +23
   System.Lazy`1.CreateValue() +416
   System.Lazy`1.LazyInitValue() +152
   System.Lazy`1.get_Value() +75
   Orchard.ContentManagement.DefaultContentManager.New(String contentType) in DefaultContentManager.cs:76
   Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options, QueryHints hints) in DefaultContentManager.cs:199
   Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options) in DefaultContentManager.cs:111
   Orchard.ContentManagement.DefaultContentQuery.b__0(ContentItemVersionRecord x) in DefaultContentQuery.cs:148
   System.Linq.WhereSelectListIterator`2.MoveNext() +104
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +381
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
   Orchard.ContentManagement.DefaultContentQuery.Slice(Int32 skip, Int32 count) in DefaultContentQuery.cs:146
   Orchard.ContentManagement.ContentQuery`1.Orchard.ContentManagement.IContentQuery.Slice(Int32 skip, Int32 count) in DefaultContentQuery.cs:195
   Orchard.Core.Settings.Services.SiteService.b__0(AcquireContext`1 ctx) in SiteService.cs:30
   Orchard.Caching.Cache`2.CreateEntry(TKey k, Func`2 acquire) in Cache.cs:57
   Orchard.Caching.<>c__DisplayClass2.b__0(TKey k) in Cache.cs:19
   System.Collections.Concurrent.ConcurrentDictionary`2.AddOrUpdate(TKey key, Func`2 addValueFactory, Func`3 updateValueFactory) +125
   Orchard.Caching.Cache`2.Get(TKey key, Func`2 acquire) in Cache.cs:17
   Orchard.Caching.DefaultCacheManager.Get(TKey key, Func`2 acquire) in DefaultCacheManager.cs:33
   Orchard.Core.Settings.Services.SiteService.GetSiteSettings() in SiteService.cs:29
   Orchard.Settings.CurrentSiteWorkContext.Get(String name) in CurrentSiteWorkContext.cs:13
   Orchard.Environment.<>c__DisplayClass7`1.b__2(IWorkContextStateProvider wcsp) in WorkContextImplementation.cs:32
   System.Linq.WhereSelectArrayIterator`2.MoveNext() +66
   System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate) +161
   Orchard.Environment.WorkContextImplementation.FindResolverForState(String name) in WorkContextImplementation.cs:32
   System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72
   Orchard.Environment.WorkContextImplementation.GetState(String name) in WorkContextImplementation.cs:27
   Orchard.WorkContext.get_CurrentSite() in WorkContext.cs:52
   Contrib.Cache.Filters.OutputCacheFilter.b__1(AcquireContext`1 context) +63
   Orchard.Caching.Cache`2.CreateEntry(TKey k, Func`2 acquire) in Cache.cs:57
   Orchard.Caching.<>c__DisplayClass2.b__0(TKey k) in Cache.cs:19
   System.Collections.Concurrent.ConcurrentDictionary`2.AddOrUpdate(TKey key, Func`2 addValueFactory, Func`3 updateValueFactory) +125
   Orchard.Caching.Cache`2.Get(TKey key, Func`2 acquire) in Cache.cs:17
   Orchard.Caching.DefaultCacheManager.Get(TKey key, Func`2 acquire) in DefaultCacheManager.cs:33
   Contrib.Cache.Filters.OutputCacheFilter.OnActionExecuting(ActionExecutingContext filterContext) +531
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +41
   System.Web.Mvc.<>c__DisplayClass17.b__14() +22
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +256
   System.Web.Mvc.<>c__DisplayClass17.b__14() +22
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311
   System.Web.Mvc.Controller.ExecuteCore() +105
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +87
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.b__5() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.b__0() +19
   System.Web.Mvc.Async.<>c__DisplayClass8`1.b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.<>c__DisplayClasse.b__d() +31
   System.Web.Mvc.SecurityUtil.b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in ShellRoute.cs:147
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629708
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
It looks to be related to 4.0->4.5 migration issues. Can anyone help with this?

Coordinator
Sep 20, 2012 at 11:52 PM

It seems that moving to 4.5 has broken the website. You should be able to request to run under 4.0, there is a setting for that in IIS.

Sep 21, 2012 at 12:22 AM

Unfortunately, the only options I have are:

4.0 x86 (Currently set)

4.0 x64

2.0 x86

2.0 x64

 

And doesn't installing 4.5 overwrite 4.0?

Sep 21, 2012 at 4:19 AM

I'm having this exact same problem.  My site is hosted by Arvixe.  Are there any known workarounds for this.  Arvixe also only lets me run as IIS 4.0.

Sep 21, 2012 at 1:19 PM

Yes, 4.5 install isn't a side-by-side install... So if something about 4.5 is breaking it and you have a pressing need to resolve (and you control the web server) than I think your best bet unfortunately is to uninstall 4.5. If you are on a shared host then not sure what to suggest right now. I am a shared hoster and was trying this out just to verify compat. Trying to recall now, since it has been a few weeks, but I think I actually tested AutoFac independently on 4.5 under medium trust and had no issues. Not a 1:1 comparison in terms of how Orchard uses it for DI, but still...

Re: IIS setting, not sure what Sebastien is referring to exactly. App pool managed runtime version is 2 or 4 as it's based on the CLR...

As an aside, I ran into another issue with 4.5 and DotNetNuke. After digging into it I was able to resolve it, but it seemed to be potentially related to CAS demands actually being honored in 4.5 where in 4.0 maybe they weren't working properly...?

-Mike

Sep 21, 2012 at 3:17 PM

Same problem here! Only, it's happening to me even on dev machine when I uncomment <trust> element in web.config. And it's on Orchard 1.4.2..

Sep 21, 2012 at 5:35 PM
Edited Sep 21, 2012 at 5:35 PM

UPDATE:

Once I change the application pool to use ASP.NET 4.0 (Integrated Pipeline) instead of ordinary ASP.NET 4.0, it starts to work under medium trust. Somebody should probably write this somewhere in the documentation in case people start wondering why isn't it working..

Sep 21, 2012 at 5:48 PM

Fera, I think that fix is specific to your scenario. I have Orchard 1.5.1 throwing the VerificationException with the app pool configured to use Integrated pipeline mode.

-Mike

Oct 1, 2012 at 11:40 PM

I hope this gets sorted soon. It's been over a week and no resolution as of yet.

Coordinator
Oct 2, 2012 at 2:24 AM

You hope what gets sorted soon? There are quite a few different things in this thread.

Oct 2, 2012 at 2:40 AM

I hope that using Orchard 1.5.1 on ASP.Net 4.5 x86 integrated pipeline under medium trust is fixed so that AutoFac doesn't dump out with an "Operation could destabilize the runtime" error.