November Happy Hour will be moved to Thursday December 5th.

MVC routing attributes problem in Foundation with EPiServer.Insight

Vote:
 

Hi!

I'm tying to install our plugin to ensure the functionallity. I have downloaded and installed the latest Foundation version and that works just fine.
I have installed our plugin and the site works is running but when entering the backoffice I get an exception. Neither edit or admin will not load.

The exception is:

Exception information: 
    Exception type: NullReferenceException 
    Exception message: Object reference not set to an instance of an object.
   at EPiServer.Insight.UI.ProfilesRolesRepository.GetRolesForUser(String userName)
   at EPiServer.Insight.UI.ProfilesMenuProvider.AddProfilesMenuItems(ICollection`1 menuItems)
   at EPiServer.Insight.UI.ProfilesMenuProvider.GetMenuItems()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at EPiServer.Shell.Navigation.MenuAssembler.GetMenuItems(String parentPath, Int32 relativeDepth)
   at EPiServer.Shell.Navigation.MenuAssembler.GetMenuHierarchy(String rootPath, Int32 relativeDepth, String selectionPath)
   at EPiServer.Shell.Web.Internal.NavigationService.GetCurrentProduct()
   at EPiServer.Shell.Web.Internal.NavigationService.GetCurrentProductId()
   at EPiServer.Shell.Navigation.MenuHelper.CreateMenuRootElement()
   at EPiServer.Shell.Navigation.MenuHelper.CreatePlatformNavigationMenu()
   at EPiServer.Shell.Web.UI.WebControls.PlatformNavigationMenu.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer)
   at System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer)
   at ASP.episerver_cms_masterpages_frameworks_framework_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in http://server/episerver/CMS/MasterPages/Frameworks/Framework.Master:line 8
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Page.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

I have managed to find out that there is one line of code causing this and that it is this line:

RouteTable.Routes.MapMvcAttributeRoutes();

Our plugin is using routing attributes so we need to map these on startup.

Removing that line of code, backoffice works just fine, my menu items are loading correctly but routing does not work of course.
Uninstallning EPiServer.Insight and every thing works just fine.

Does anyone have a clue why MapMvcAttributeRoutes does not work with EPiServer.Insight?

Thanks!

/Kristoffer

#226299
Aug 10, 2020 15:35
Vote:
 

Hi Kristoffer,

Most likely this is similiar case as it can be with Web API and the call to 'MapHttpAttributeRoutes()'. I've writen a blog post about the Web API and multiple calls to 'MapHttpAttributeRoutes()'. So in your case if the MapMvcAttributeRoutes() is called multiple times the issue comes BUT kind of if you remove your codes call to that it should just start working. If you know how to use ILSpy or a like software you could have a look at the Insights code and then know what it does and what might cause the issue for the routing to not work. So most likely this is related to the order where the call is done to register the attribute based MVC routing.

#226676
Aug 18, 2020 6:49
Vote:
 

Thanks Antto, I will look into that.

/Kristoffer

#226678
Aug 18, 2020 9:46
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.