System.InvalidCastException: Unable to cast object of type 'System.Web.Mvc.Routing.RouteCollectionRoute' to type 'System.Web.Routing.Route'.
Seeing a route enumeration error in diagnostics, any ideas? Umbraco 8.17.1 God Mode 2.4.1
Might be associated with Swashbuckle 5.6.0 (SwaggerApi) ?
Exception
System.InvalidCastException: Unable to cast object of type 'System.Web.Mvc.Routing.RouteCollectionRoute' to type 'System.Web.Routing.Route'.
at Diplo.GodMode.Services.DiagnosticService.<>c.<GetDiagnosticGroups>b__6_4(RouteBase r)
at System.Linq.Enumerable.<>c__DisplayClass7_0`3.<CombineSelectors>b__0(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
at Diplo.GodMode.Services.DiagnosticService.GetDiagnosticGroups()
at lambda_method(Closure , Object , Object[] )
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
Could it be
section.Diagnostics.AddRange(RouteTable.Routes.Select(r => (Route)r).Select(r => new Diagnostic(r.RouteHandler.GetType().Name, r.Url)));
might need to be..
section.Diagnostics.AddRange(RouteTable.Routes.OfType<Route>().Select(r => new Diagnostic(r.RouteHandler.GetType().Name, r.Url)));
Dropping webApi routes?
Also having issues using RouteTable.Routes.MapMvcAttributeRoutes(); and
using Microsoft.Owin.Security;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
using Umbraco.Core.Logging;
namespace LP.Web.Controllers
{
[RoutePrefix("Account")]
public class AccountSurfaceController : PluginController
{
[Route("LogIn")]
public ActionResult LogIn(string returnUrl)
{
// Use the default policy to process the sign up / sign in flow
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties {
//RedirectUri = "/"
RedirectUri = returnUrl ?? "/"
});
return new HttpUnauthorizedResult();
}
}
}
Means r.RouteHandler is null ??

It would appear that these end up as LinkGenerationRoute and as such don't have RouteHandlers?
Hi! Thanks for reporting this. It's not one I've seen before or had reported before. Is it a standard Umbraco site or are you doing anything "custom" with routing?
I think with something like this, that I can't replicate, then would you be able to find a fix yourself? Doesn't need to be a PR, just the line of code. I'm guessing some kind of null check would be needed?
Sorry been a while.. Had it crop up again on an old site.. so implemented a fix
section = new DiagnosticSection("MVC Routes");
section.Diagnostics.AddRange(RouteTable.Routes.OfType<Route>().Select(r => new Diagnostic(r?.RouteHandler?.GetType()?.Name ?? "n/a", r?.Url ?? string.Empty)));
sections.Add(section);
results in this for those System.Web.Mvc implementations..
namespaceCode.Controllers.Surface
{
/// <summary>
/// Summary description for DevelopmentInfoController
/// </summary>
[RoutePrefix("api/devinfo")]
public class DevelopmentInfoController : RenderMvcController
{
public DevelopmentInfoController()
{
}
[HttpGet]
[Route("getdevbox/{id}")]
public ActionResult GetDevelopmentInfo(int id)
{
var node = Umbraco.Content(id);
if (node != null)
{
return PartialView("~/Views/Partials/Content/DevelopmentBox.cshtml", node);
}
else
{
return null;
}
}
}
}
Cheers! Will look at committing this to the main source code next time I'm working on it. Thanks for helping.