4
Vote

Orchard 1.7 Move taxonomy term Error

description

When using the move comand on the taxonomy term in the dashboard i get this error:

An unhandled exception has occurred and the request was terminated. Please refresh the page. If the error persists, go back
Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object. at Orchard.Taxonomies.Services.TaxonomyService.<>c__DisplayClass22.<GetChildren>b__21(TermPart x) at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Orchard.Taxonomies.Models.TermPart.Sort(IEnumerable1 terms) at Orchard.Taxonomies.Services.TaxonomyService.GetChildren(TermPart term) at Orchard.Taxonomies.Services.TaxonomyService.MoveTerm(TaxonomyPart taxonomy, TermPart term, TermPart parentTerm) at Orchard.Taxonomies.Controllers.TermAdminController.MoveTerm(Int32 taxonomyId, Int32 selectedTermId, String termIds) at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation)

comments

nduarte wrote Aug 7, 2013 at 12:17 AM

Forgot to mention, using orchard 1.7

jhenderson22 wrote Aug 30, 2013 at 12:41 PM

I am also getting this error...

jhenderson22 wrote Sep 2, 2013 at 2:06 AM

Although, I am getting this error while using the taxonomy in a filter for a query...

nduarte wrote Sep 24, 2013 at 9:36 PM

Sebastien,
When i opened this issue, i forgot to mention (actually i found out later) that this only happens when the taxonomy and terms are created in code using the taxonomy and contentManager services, instead of the dashboard.
In my case, i was creating the taxonomy and terms on a FeatureEventHandler of my module.
Hope this helps in the repro of the bug.

Jetski5822 wrote Jun 23 at 9:37 PM

hey nduarte - Do you have the code you were using to create the taxonomy and terms?

nduarte wrote Jun 25 at 4:43 PM

hey Jetski5822,

You have a complete demo for this in a Plurasight course named "Advanced Orchard".
The source code for the demo is publicly available on bitbucket:
https://bitbucket.org/kevinkuebler/pluralsight.movies/src/0b66885d0593?at=default

The following link will take you directly to the featureeventhandler:
https://bitbucket.org/kevinkuebler/pluralsight.movies/src/0b66885d05936a56bfc46cd56cf23741e43b9209/Handlers/MovieFeatureEventHandler.cs?at=default

Hope it helps.

Nuno.

Jetski5822 wrote Jun 25 at 5:37 PM

This is one I did a while ago.. https://github.com/Jetski5822/Contrib.ImportExport/blob/master/Services/TaxonomyImportService.cs

I think
                var genre = _contentManager.New<TaxonomyPart>("Taxonomy");
                genre.Name = "Genre";
                _contentManager.Create(genre, VersionOptions.Published);
should be
                var genre = _contentManager.New<TaxonomyPart>("Taxonomy");
                genre.Name = "Genre";
                genre.Slug = "genre";
                _contentManager.Create(genre, VersionOptions.Published);
               _taxonomyService.CreateTermContentType(genre.As<TaxonomyPart>());
and I think
        private void CreateTerm(TaxonomyPart genre, string genreName) {
            var term = _taxonomyService.NewTerm(genre);
            term.Name = genreName;
            _contentManager.Create(term, VersionOptions.Published);
        }
should be
    private void CreateTerm(TaxonomyPart genre, string genreName) {
        var term = _taxonomyService.NewTerm(genre);
        term.Name = genreName;
        term.Weight = 0;
        term.Container = genre.ContentItem;
        _contentManager.Create(term, VersionOptions.Published);
    }


Can you try those changes?

nduarte wrote Jun 25 at 6:32 PM

This was a long time ago, a that time i was trying things out.

But looking at your code
` private void CreateTerm(TaxonomyPart genre, string genreName) {
    var term = _taxonomyService.NewTerm(genre);
    term.Name = genreName;
    term.Weight = 0;
    term.Container = genre.ContentItem;
    _contentManager.Create(term, VersionOptions.Published);
}`
``` and comparing it with the source Orchard.Taxonomies\Controllers\TermAdminController.cs

it makes sense, term.Container was missing, but i believe you must set the term.Path as well.

At the moment i´m working on a project (deadline is next week) i don´t have much time to test it, but as soon as in can, i will also try it.

Nuno