Object reference not set to an instance of an object. when creating a Hierarchical Taxonomies and Taxons
Hi there,
I am trying to export an existing site to a new platform using Sitefinity. So, I am trying to export a list of categories and subcategories and in which I am using this code :
private
static
void
ImportCategories()
TaxonomyManager manager = TaxonomyManager.GetManager();
var taxonomy = manager.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name ==
"Categories"
).SingleOrDefault();
if
(taxonomy ==
null
)
return
;
var listCateg = ImportCategAndSubCateg.GetListCategories();
foreach
(var itemCateg
in
listCateg)
var rootTaxonCateg = manager.CreateTaxon<HierarchicalTaxon>();
rootTaxonCateg.Name = itemCateg.Name;
rootTaxonCateg.Title = itemCateg.Name;
rootTaxonCateg.Description = itemCateg.Description;
taxonomy.Taxa.Add(rootTaxonCateg);
var listSubCateg = ImportCategAndSubCateg.GetSubCategPerCateg(itemCateg.ID);
foreach
(var itemSubCateg
in
listSubCateg)
var taxonSubCateg = manager.CreateTaxon<HierarchicalTaxon>();
taxonSubCateg.Title = itemSubCateg.Name;
rootTaxonCateg.Subtaxa.Add(taxonSubCateg);
var listChildSubCateg = ImportCategAndSubCateg.GetSubCategPerSubCateg(itemCateg.ID, itemSubCateg.SubcategParentId);
foreach
(var itemChildSubCateg
in
listChildSubCateg)
var taxonChildSubCateg = manager.CreateTaxon<HierarchicalTaxon>();
taxonChildSubCateg.Title = itemChildSubCateg.Name;
taxonSubCateg.Subtaxa.Add(taxonChildSubCateg);
manager.SaveChanges();
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 56:
Line 57:
Line 58: manager.SaveChanges();
Line 59:
Line 60:
Source File: C:\Code\SmartBizMart\SmartBizMart\Widgets\Migration\MigrationTool.ascx.cs Line: 58
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Telerik.Sitefinity.Security.AuthorizationPermissionProvider.AuthorizeInput(IMethodInvocation input) +3234
Telerik.Sitefinity.Security.SitefinityAuthorizationCallHandler.Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) +274
Telerik.Microsoft.Practices.Unity.InterceptionExtension.HandlerPipeline.Invoke(IMethodInvocation input, InvokeHandlerDelegate target) +221
Telerik.Microsoft.Practices.Unity.InterceptionExtension.PolicyInjectionBehavior.Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext) +199
Telerik.Microsoft.Practices.Unity.InterceptionExtension.InterceptionBehaviorPipeline.Invoke(IMethodInvocation input, InvokeInterceptionBehaviorDelegate target) +221
DynamicModule.ns.Wrapped_OpenAccessTaxonomyProvider_4a8e5586d1fd436e8695ba4d12297e8e.CommitTransaction() +181
Telerik.Sitefinity.Data.ManagerBase`1.SaveChanges() +136
SitefinityWebApp.Widgets.Migration.MigrationTool.ImportCategories() in C:\Code\SmartBizMart\SmartBizMart\Widgets\Migration\MigrationTool.ascx.cs:58
SitefinityWebApp.Widgets.Migration.MigrationTool.btnOk_Click(Object sender, EventArgs e) in C:\Code\SmartBizMart\SmartBizMart\Widgets\Migration\MigrationTool.ascx.cs:23
Telerik.Web.UI.RadButton.OnClick(ButtonClickEventArgs e) +126
Telerik.Web.UI.RadButton.RaisePostBackEvent(String eventArgument) +265
Telerik.Web.UI.RadButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +42
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Did anyone ever find a solution to this. I upgrade to 5.1 and am getting this error as well?
Hi Victor,