OrchardCMS / Orchard

Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform.
https://orchardproject.net
BSD 3-Clause "New" or "Revised" License
2.38k stars 1.12k forks source link

1.5 RC NullReferenceException at CustomForms.Security.AuthorizationEventHandler #2628

Closed orchardbot closed 9 years ago

orchardbot commented 12 years ago

DavidHayden created: https://orchard.codeplex.com/workitem/18801

When editing role-based permissions we get a NullReferenceException filling up the Log File:

2012-07-10 14:31:40,264 [80] Orchard.Exceptions.DefaultExceptionPolicy - An unexpected exception was caught System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Orchard.CustomForms.Security.AuthorizationEventHandler.Adjust(CheckAccessContext context) --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Orchard.Events.DefaultOrchardEventBus.TryInvokeMethod(IEventHandler eventHandler, Type interfaceType, String methodName, IDictionary2 arguments, IEnumerable& returnValue) in D:\orchard-src-1.5-rc\src\Orchard\Events\DefaultOrchardEventBus.cs:line 83 at Orchard.Events.DefaultOrchardEventBus.TryInvoke(IEventHandler eventHandler, String interfaceName, String methodName, IDictionary2 arguments, IEnumerable& returnValue) in D:\orchard-src-1.5-rc\src\Orchard\Events\DefaultOrchardEventBus.cs:line 68 at Orchard.Events.DefaultOrchardEventBus.TryNotifyHandler(IEventHandler eventHandler, String messageName, String interfaceName, String methodName, IDictionary`2 eventData, IEnumerable& returnValue) in D:\orchard-src-1.5-rc\src\Orchard\Events\DefaultOrchardEventBus.cs:line 52

Here is the culprit: "context.content" is Null and causes the exception. ///

/// Alters the Edit permission requested by the Contents module before editing a form. Returns a Submit permission instead. ///

[UsedImplicitly] public class AuthorizationEventHandler : IAuthorizationServiceEventHandler { public void Checking(CheckAccessContext context) { } public void Complete(CheckAccessContext context) { }

public void Adjust(CheckAccessContext context) {
    if (!context.Granted 
        && context.Permission.Name == Orchard.Core.Contents.Permissions.EditContent.Name 
        && context.Content.ContentItem.ContentType == "CustomForm") {

        context.Adjusted = true;
        context.Permission = Permissions.CreateSubmitPermission(context.Content.ContentItem.As<CustomFormPart>().ContentType);
    }
}

}

Regards,

Dave

orchardbot commented 12 years ago

DavidHayden commented:

Actually, the code above gets run a lot and causes a flood of exceptions.

orchardbot commented 12 years ago

@sebastienros commented:

Fixed in changeset f4c1b358bd44

orchardbot commented 11 years ago

@sfmskywalker commented:

Fixed in changeset 28e378dfaedc3d27cff4f2a22c0720e6d33f4b49