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.37k stars 1.12k forks source link

RuntimeBinderException when displaying a MenuItem #8654

Closed AndreaPiovanelli closed 1 year ago

AndreaPiovanelli commented 1 year ago

https://github.com/OrchardCMS/Orchard/blob/c515ce191701e770ff7231d1b973d64771c56686/src/Orchard.Web/Core/Shapes/CoreShapes.cs#L104

When calling the display of a menu item, if menu is null a RuntimeBinderException is thrown.

2023-03-07 09:12:56,132 [22] Orchard.DisplayManagement.Implementation.DefaultDisplayManager - ECommerce - RuntimeBinderException thrown from Action1 by System.Action1[[Orchard.DisplayManagement.Implementation.ShapeDisplayingContext, Orchard.Framework, Version=1.10.3.0, Culture=neutral, PublicKeyToken=null]] [https://localhost/OrchardLocal/ECommerce/Contents/Item/Display/406] Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: La corrispondenza migliore del metodo di overload per 'Orchard.Core.Shapes.CoreShapes.EncodeAlternateElement(string)' presenta alcuni argomenti non validi in CallSite.Target(Closure , CallSite , CoreShapes , Object ) in System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) in Orchard.Core.Shapes.CoreShapes.<Discover>b__12_6(ShapeDisplayingContext displaying) in D:\Laser.Orchard\Laser.Orchard\Orchard\src\Orchard.Web\Core\Shapes\CoreShapes.cs:riga 104 in Orchard.DisplayManagement.Implementation.DefaultDisplayManager.<>c__DisplayClass15_0.<Execute>b__1(Action1 action) in D:\Laser.Orchard\Laser.Orchard\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:riga 80 in Orchard.InvokeExtensions.Invoke[TEvents](IEnumerable1 events, Action1 dispatch, ILogger logger) in D:\Laser.Orchard\Laser.Orchard\Orchard\src\Orchard\InvokeExtensions.cs:riga 17`

The Display of a menu item shouldn't normally get called if not by a forced call, but adding a null check may easily solve the issue.