Dresel / RouteLocalization

RouteLocalization is an MVC and Web API package that allows localization of your attribute routes.
MIT License
67 stars 13 forks source link

Object reference not set to an instance of an object #22

Closed brgrz closed 10 years ago

brgrz commented 10 years ago

What could be the reason for getting the above exception when doing route translation registration:

        localization.ForCulture("en")
            .ForController<DirectoryCategoryController>()
            .ForAction(x => x.Directory())
            .AddTranslation("directory");
Dresel commented 10 years ago

Can you show me the complete route configuration + stacktrace?

brgrz commented 10 years ago

Here's the stack trace. The registration is pretty much the same as in your sample project (copypasted with some minor tweaks, nothing crucial is missing). I guess it cannot find the controller and action. FYI, I am using T4MVC if that makes any difference:

[NullReferenceException: Object reference not set to an instance of an object.] RouteLocalization.Mvc.Extensions.RouteEntryCollectionExtensions.MatchesControllerAndAction(Route route, String controller, String action) +57 RouteLocalization.Mvc.Extensions.<>c__DisplayClass8.<GetSimiliarUntranslatedRoutes>b__4(LocalizationCollectionRoute x) +22 System.Linq.WhereEnumerableIterator1.MoveNext() +139 System.Collections.Generic.List1..ctor(IEnumerable1 collection) +381 System.Linq.Enumerable.ToList(IEnumerable1 source) +58 RouteLocalization.Mvc.Extensions.RouteEntryCollectionExtensions.GetSimiliarUntranslatedRoutes(ICollection1 routeEntries, String culture, String controller, String action, String controllerNamespace, ICollection1 actionArguments) +204 RouteLocalization.Mvc.Extensions.RouteEntryCollectionExtensions.GetFirstUntranslatedRoute(ICollection1 routeEntries, String culture, String controller, String action, String controllerNamespace, ICollection1 actionArguments) +20 RouteLocalization.Mvc.RouteTranslator.AddTranslation(String url, String culture, String controller, String action, String controllerNamespace, ICollection1 actionArguments) +155 RouteLocalization.Mvc.RouteTranslator1.AddTranslation(String url, String culture, String controller, String action, String controllerNamespace, ICollection1 actionArguments) +49 RouteLocalization.Mvc.RouteTranslator1.AddTranslation(String url) +86 pending.Web.Routing.FrontendRoutes.RegisterFrontendRoutes(Localization localization) in f:\pending\Projects\...\pending.Web\Routing\FrontendRoutes.cs:14 pending.Web.Routing.RouteConfig.<RegisterRoutes>b__1(Localization localization) in f:\pending\Projects\...\pending.Web\Routing\RouteConfig.cs:883

Dresel commented 10 years ago

The sample project does use T4MVC too, so this should make no difference.

You have an controller level route defined?

brgrz commented 10 years ago

In sample project in RouteConfig.cs what did you mean with the following comment?

        // Add translations
        // You can translate every specific route that contains default Controller and Action (which MapMvcAttributeRoutes does)
        routes.Localization(configuration =>
brgrz commented 10 years ago

I did have controller level route defined and I just removed it. I also removed a couple of classic routes registered with .MapRoute(). The exception is still there.

Dresel commented 10 years ago

I can reproduce this exception with controller level route - but if say you have none, I can't reproduce it. Please post a minimal configuration (RouteConfig.cs / Controller.cs) that reproduces this issue.

Dresel commented 10 years ago

I just uploaded a new package that fixes the controller level attribute route issue. I also added controller level attribute routes to the sample.

If your object reference exception still exists, post your configuration so I can reproduce it.

brgrz commented 10 years ago

After updating I made some progress, now it says: No Route found for given Controller 'DirectoryCategory' and Action 'Directory'.

brgrz commented 10 years ago

I'm playing with RoutePrefix and route setups, will let you know how that goes..

brgrz commented 10 years ago

After adding RoutePrefix to controller and using SetRoutePrefix() things started to work. If I run into more issues, I will open new issue.