-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NullReferenceException #416
Comments
I downgrade to 4.6.18 and works fine. |
Thanks for the report. I know this is happening because Best guess is that you have an invalid Area configuration in your application. I have only found one way to configure Areas that works with MvcSiteMapProvider, which is using conventions all the way. Once you have worked out what is wrong with your configuration, I would appreciate you building a sample project showing how you get this failure and either post it on GitHub or make it available for download. I will add a check for a null controller type in this case anyway because this is for interoperability with MvcCodeRouting which doesn't even support Areas, but there should probably be an exception put in for invalid Area configurations so they will work with security trimming, rather than just failing silently like they are now. |
…ions caused by ControllerTypeResolver returning null.
I believe that in my case the problem was null PARENT_ID. I updated the values for 0 and updated to version 4.6.20 and is working. |
Thanks, but I am more interested to know what change to your configuration you need to make to get it working with 4.6.19. If your root node is an [MvcSiteMapNodeAttribute], its parent ID should be null, but all other nodes should have one. Are you using Areas in your application? If so, have you configured your routes to include the namespace of the controllers? Are you using an AreaRegistration class or have you set up custom routing for the Areas? If you are not using Areas, I suppose the other thing that could cause this is if one of your nodes is missing a Controller property/attribute, but I was unable to find a way to make this happen that would cause this failure. |
No I'm not using areas. I downgraded to version 4.6.19 and still does not work, I honestly have no idea of what can be. I did not make any changes in my code except change the null value to 0 in parent_id in the database and build 19 is still not working. In build 18 and 20 is OK. My Mvc.sitemap <?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd">
<mvcSiteMapNode key="0" title="root" clickable="false">
<mvcSiteMapNode title="" dynamicNodeProvider="AppConsig.Web.Gestor.AppDynamicNodeProvider, AppConsig.Web.Gestor"/>
</mvcSiteMapNode>
</mvcSiteMap> and my dynamic node provider public class AppDynamicNodeProvider : IDynamicNodeProvider
{
private readonly AppContext _context = new AppContext();
public IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
{
var usuarioLogado = ((AppPrincipal)HttpContext.Current.User);
var permissoes = _context.Usuarios.Include(u => u.Perfil)
.Include(u => u.Perfil.Permissoes)
.First(u => u.Id == usuarioLogado.Id).Perfil.Permissoes;
var nodeList = new List<DynamicNode>();
foreach (var permissao in permissoes)
{
var dNode = new DynamicNode
{
Key = permissao.Id.ToString(),
ParentKey = permissao.ParenteId.ToString(),
Title = permissao.Nome,
Description = permissao.Descricao,
Url = permissao.Url,
Action = permissao.Acao,
Controller = permissao.Controle,
Order = permissao.Ordem
};
//Quando for CRUD
if (permissao.EhCRUD)
{
var cList = permissao.Atributos.Split(';');
dNode.PreservedRouteParameters = cList;
}
dNode.Attributes.Add("icon", permissao.ClasseIcone);
dNode.Attributes.Add("visibility", permissao.MostrarNoMenu ? string.Empty : "!MenuHelper");
nodeList.Add(dNode);
}
return nodeList;
}
public bool AppliesTo(string providerName)
{
if (string.IsNullOrEmpty(providerName))
return false;
return GetType() == Type.GetType(providerName, false);
}
} in Database
|
After the last update my solution now has the following error with the MVCSiteMapProvider.
View:
Stack Trace:
Someone would have any suggestions of what to do to find out the problem?
I've tried to debug but could not view the information in Html.MvcSiteMap ().
The text was updated successfully, but these errors were encountered: